Yep. I left it out for brevity. Besides, I don't think Hibernate would be able to do the inserts if I hadn't defined a PK, no?
Anyway, here it is: @Column(name="idAAndBJoin") @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() Man, I got quite excited for a minute there. But alas, that's not the problem ... Bob Mike Horwitz wrote: > > Have you assigned a primary key field to your AAndBJoin object? > > Mike. > > On 10/22/07, syg6 <[EMAIL PROTECTED]> wrote: >> >> >> Hello listers. >> >> I have posted on this before. I got no replies, either here or over at >> hibernate.org. So I parked the issue and moved on but now I have to deal >> with it. Because of my limited Hibernate knowledge, I am not even really >> sure of what things to try anymore. Can someone shed some light on this >> problem for me? >> >> I have two Objects, ObjectA and ObjectB. They have a ManyToMany >> relationship >> with attributes, meaning they have a join table with IdObjectA and >> IdObjectB >> as foreign keys and some attributes. As recommended by the Hibernate >> docs, >> I >> create a class, AAndBJoin we'll call it. Here's what it all looks like: >> >> public class ObjectA >> { >> private Set<AAndBJoin> aAndBJoins; >> >> @OneToMany(mappedBy="ObjectA", fetch = FetchType.EAGER, cascade = { >> CascadeType.ALL }) >> public Set<AAndBJoin> getAAndBJoins () >> >> public class ObjectB >> { >> private Set<AAndBJoin> aAndBJoins; >> >> @OneToMany(mappedBy="ObjectB") >> public Set<AAndBJoin> getAAndBJoins () >> >> public class AAndBJoin >> { >> private ObjectA objectA; >> private ObjectB objectB; >> >> @ManyToOne >> @JoinColumn(name="idObjectA") >> public ObjectA getObjectA() >> >> @ManyToOne >> @JoinColumn(name="idObjectB") >> public ObjectB getObjectB() >> >> The problem is that when I save an ObjectA, with its associated Set of >> AAndBJoin Objects, ONLY inserts are done in the AAndBJoin table in the >> database, any existing information is NOT being updated or deleted. So if >> I >> start off with 2 AAndBJoin Objects and add 1, instead of having 3 I now >> have >> 5 because 3 inserts are performed, one for each AAndBJoin Object sent to >> the >> FormController from the .jsp, but the original 2 are left untouched. >> >> Do I have to play with the AAndBJoin Object, like add Cascade information >> or >> something else? In the example there was none, and I have tried putting >> Cascade.ALL for the two getters, no dice. Or perhaps I have to do >> something >> manually, like call session.flush() or something, to get Hibernate to >> (worst >> case scenario) delete the info in the AAndBJoin table first before >> inserting? I am not sure even how to do this since Spring is in the mix. >> I >> have tried debugging Hibernate to see what's going on but since Spring is >> involved and uses Reflection and AopProxies and all kinds of stuff I >> haven't >> a clue about, I never actually see any Hibernate code executed ... >> >> I would really appreciate some help on this one! >> >> Bob >> -- >> View this message in context: >> http://www.nabble.com/Many-to-many-collection-problem-tf4670322s2369.html#a13341640 >> Sent from the AppFuse - User mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> 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#a13343413 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]