• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate many-to-many problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ May 08, 2006: Message edited by: Angela Stempfel ]
 
Angela Stempfel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Evil is afoot. But this tiny ad is just an ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic