Well, I guess if I changed the idObjectA to 'not null' in the AAndBJoin table, the insert would fail. But regardless, I *need* this column to be properly saved, otherwise the Collection of AAndBJoin objects won't be loaded when I load an ObjectA.
I'm not sure what to do at this point. Hibernate handles all other Join tables properly. For example, in this same ObjectA I have a 'normal' Collection of ObjectC: ObjectA: @ManyToMany ( targetEntity=com.myco.myapp.model.ObjectC.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE },fetch = FetchType.EAGER) @JoinTable ( name="objectaobjectc", [EMAIL PROTECTED](name="idObjectA",nullable=false)}, [EMAIL PROTECTED](name="idObjectC",nullable=false)}) public Set<ObjectC> getObjectCs() ObjectC: @ManyToMany ( cascade = { CascadeType.ALL }, mappedBy = "objectCs", targetEntity = ObjectC.class) public Set<ObjectA> getObjectAs() When I say 'normal', I mean it creates a Join table, but without attributes. It has only two fields, idObjectA and idObjectC. So I don't have to create my Model class, AAndCJoin. And there is no problem, even when creating a new ObjectA, saving the idObjectA field in the Join table. Hibernate seems to be smart enough to save the ObjectA first (thus creating an idObjectA) and then saves the ObjectC(s). But with the other Collection, since I am using my own Model class, AAndBJoin, when I create a new ObjectA, and associate AAndBJoin Objects, they are saved without idObjectA. Something else I have noticed: deleting members of the AAndBJoin Collection seems to be working, more or less, now that I put the DELETE_ORPHAN Hibernate Annotation. But there is one case where it does NOT work -- when you delete all of the elements. When you delete all of the elements, the 'AAndBJoin' Request parameter is of course null. What Hibernate should do in this case is delete all elements. But what it in fact does, is nothing. It seems that in order for Hibernate to properly delete elements from a Collection, at least one element has to be sent in the Request. Thus, if you had 4 and deleted 3, 1 element is sent in the Request and Hibernate compares the Collection before and after, and properly deletes 3. But if you delete all 4, in the Request 'null' is received, Hibernate seems to do no comparison, and deletes nothing. Ugh. Hibernate ... a riddle, wrapped in a mystery, inside an enigma. Bob DNewfield wrote: > > syg6 wrote: >> The only problem left is that when I create a new ObjectA and at the same >> time associate AAndBJoin objects (as opposed to first saving a new >> ObjectA >> and then editing it and associating AAndBJoin objects), the associated >> AAndBObjects are saved in the database with idObjectA=null, thus they are >> not properly associated. > > If you were using xdoclet (which generates xml) instead of JPA I'd > suggest you have insert="false" on the association, which tells > Hibernate not to include that column in the row when inserting a new > entry. Don't know how that translates to the JPA version. If that > column were "not-null", though, you'd catch the problem earlier... > > -Dale > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/Many-to-many-collection-problem-tf4670322s2369.html#a13485007 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]