Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate many-to-many problem

 
Angela Stempfel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Angela Stempfel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ May 08, 2006: Message edited by: Angela Stempfel ]
 
Angela Stempfel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic