Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Many to Many Relation Error Driving Me Mad

 
rodrigo bengoechea
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!, I'm developing my first application using hibernate and I'm having an error while I'm mapping a many to many relation. I've tried several times to fix it but I haven't been able to do it so I decided to ask you.

Basically the relation is this: A Group is made of many Users and a User can be part of many Groups.

Please if anyone could tell me something it would be very useful since I have no experience with this framework. I know this post could be pretty long but I'm desperate to fix this.

Thanks in advance to everyone!
Regards.

Rodrigo

Here I give you the User class:



Here's the User hbm:



Here's the group class:



Here's the Group hbm:



Here's the code where I'm relating the user with the group:



Here's the save group method:


And Finally the stacktrace:


 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please check the values of webgroup_id and elt that the insert statement below is using. Do the values that you are trying to insert in the JOIN TABLE exist in the WebGroup and Users tables?

 
rodrigo bengoechea
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think so, how can I display the parameter's value? I'm pretty lost with this...

Thanks!
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Use log4j

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=debug

or
2. If using IDE use debugger/watch/inspect
or
3. System.out.


and "show_sql" should be set to true in hibernate.cfg.xml
 
rodrigo bengoechea
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I've used the System.out and the parameter's values are correct... could be something else?
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know that the values inserted in the JOIN table are not violating the constraints in MANY-MANY entity tables all I can suggest is(are) Junit(s).
or try inserting that row(s) using SQL in DEV DB.
 
rodrigo bengoechea
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh I've solved the problem it was a mistake in the hbm's mappings. Many thanks for all your help! Now my laptop doesn't have internet connection since I'm at work but if you want I'll post the changes in the mappings when I get home.

Thanks again!!!

Rodrigo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic