Title:
Bug 82545:(Watson Migration Closure)Problem with many-to-many and struct-based collections
| View in TrackerStatus/Resolution/Reason: Closed/Won't Fix/
Reporter/Name(from Bugbase): Bob Silverberg / Bob Silverberg (Bob Silverberg)
Created: 03/30/2010
Components: ORM Support
Versions: 9.0
Failure Type: Unspecified
Found In Build/Fixed In Build: 0000 /
Priority/Frequency: Normal / Some users will encounter
Locale/System: English / Platforms All
Vote Count: 0
Problem:
Problem with many-to-many and struct-based collections.I'm finding that I cannot add an item to a many-to-many collection when both sides of the collection are defined as structures. Here's the code:County.cfc:component persistent="true" {property name="CountryId" fieldtype="id" generator="native" type="numeric";property name="CountryCode" length="2" notnull="true";property name="Languages" fieldtype="many-to-many" cfc="Language" type="struct" structkeycolumn="LanguageName" structkeytype="string" linktable="CountryLanguage" singularname="Language" fkcolumn="CountryId";}Language.cfc:component persistent="true"{property name="LanguageId" fieldtype="id" generator="native" type="numeric";property name="LanguageName" notnull="true";property name="Countries" fieldtype="many-to-many" cfc="Country" type="struct" structkeycolumn="countrycode" structkeytype="string" linktable="CountryLanguage" inverse="true" singularname="Country" fkcolumn="LanguageId";}And here's some test code to add a new Country and Language and then add the Language to the Country:<cfscript>Country = new Country();Country.setCountryCode("CA");entitySave(Country);Language = new Language();Language.setLanguageName("English");entitySave(Language);writeDump(Country);writeDump(Language);Country.addLanguage("English",Language);Language.addCountry("CA",Country);writeDump(Country);writeDump(Language);ormFlush();</cfscript>When I run that code I see all the dumps containing the objects as I'd expect them to be, but when the ormFlush runs I get the error:Field 'countrycode' doesn't have a default valueRoot cause :java.sql.BatchUpdateException: Field 'countrycode' doesn't have a default valueAnd if I look at the SQL in the console I can see:Hibernate: insert into CountryLanguage (CountryId, LanguageName, LanguageId) values (?, ?, ?)03/24 15:02:57 [jrpp-170] HIBERNATE DEBUG - binding '1' to parameter: 103/24 15:02:57 [jrpp-170] HIBERNATE DEBUG - binding 'English' to parameter: 203/24 15:02:57 [jrpp-170] HIBERNATE DEBUG - binding '1' to parameter: 303/24 15:02:57 [jrpp-170] HIBERNATE ERROR - Field 'countrycode' doesn't have a default value03/24 15:02:57 [jrpp-170] ERROR Field 'countrycode' doesn't have a default value03/24 15:02:57 [jrpp-170] HIBERNATE ERROR - Could not synchronize database state with sessionThe error makes sense: The table expects values for CountryId, LanguageId, LanguageName *and* CountryCode, but Hibernate isn't passing the CountryCode. The objects look like they've been populated properly - Country contains Language and Language contains Country, but the SQL being generated isn't accurate. I don't know if this is a Hibernate issue or a CF issue, but I'm assuming it's a CF issue for now.Certainly just making one of the collections an array is an option, and it does eliminate the problem, but I don't think it should be impossible to have a many-to-many with two struct-based collections.
Method:
Result:
Field 'countrycode' doesn't have a default valueRoot cause :java.sql.BatchUpdateException: Field 'countrycode' doesn't have a default value
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3041239
External Customer Info:
External Company:
External Customer Name: Bob Silverberg
External Customer Email: 5AD606C248A4C7F0992015A9
External Test Config: 03/30/2010
Attachments:
Comments: