Forums Register Login

Hibernate many-to-many problem

+Pie Number of slices to send: Send
Hi all

i'm having problems with updating/inserting values in my many-to-many relationship (i have a mapping table for that).

There are 3 tables, TBENUTZER, TPROFILE and a mapping table TBENU_TPROFIL_MATRIX. The mapping table contains only two columns, a foreign-key to TBENUTZER and a foreign key to TPROFILE.

Mapping Files:
Benutzer.hbm.xml


Profil.hbm.xml



In my ManagerCode try to assing a profile to the Benutzer and then save the Benutzer object into the database:




If doing that i get the following error:



The log entries from hibernate look correct to me:



I'm also using Spring with which I configured my Managers...

Does anybody have an idea? Any helo appreciated!

Thanks
Kind Regards
Angela
+Pie Number of slices to send: Send
hi

some wild guessing :-)
from your code this looks like a biderectional relationsship between profile (Profil) and User (Benutzer) ?

where do you start/end transactions ? is the profile still attached to the session when you add the user ?
did you try to save/update the entities in the same transaction ?

btw: i would suggest you create an "addBenutzer()" method to Profil:



to maintain the relations between these two classes. it's less error prone.



wenn ich gewusst h�tte, dass man bei der landesverteidigung auf hibernate setzt :-)...


pascal
+Pie Number of slices to send: Send

[ May 08, 2006: Message edited by: Angela Stempfel ]
+Pie Number of slices to send: Send
Hi

yes its bidirectional relationship between benutzer and profil. a benutzer can have several profiles and vice versa....

All is done in one Transaction (Spring does this). If i enter the addBenutzerAndEMailCheck() method the transaction is started and when i leave a commit should be done...in my case an error occurs...
The entities are saved/updated in one transaction...

The code u said I implemented already as you can see above....

Kennen wir uns??

angela
[ May 08, 2006: Message edited by: Angela Stempfel ]
+Pie Number of slices to send: Send
hm.... i thought this could be because the DAO starts/ends the transactions and you add a Benutzer to the Profil before the Benutzer is stored (assigned an ID).
accordig to this
http://ndpsoftware.com/HibernateMappingCheatSheet.html (many-to-many bidirectional)

you should make one side "read-only".


pascal


nein, wir kennen uns nicht...
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1296 times.
Similar Threads
i have a Errors in Hibernate Query
Invalid Column Name
many side of one to many not being populated
Classcast exception
Problem with Hibernate composite key mapping
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:59:31.