permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Many to Many Relation Error Driving Me Mad Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Many to Many Relation Error Driving Me Mad" Watch "Many to Many Relation Error Driving Me Mad" New topic
Author

Many to Many Relation Error Driving Me Mad

rodrigo bengoechea
Greenhorn

Joined: Nov 15, 2008
Posts: 10
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

Joined: Apr 04, 2004
Posts: 252
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?



Thanks,
Santosh
rodrigo bengoechea
Greenhorn

Joined: Nov 15, 2008
Posts: 10
I think so, how can I display the parameter's value? I'm pretty lost with this...

Thanks!
Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
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

Joined: Nov 15, 2008
Posts: 10
Hi! I've used the System.out and the parameter's values are correct... could be something else?
Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
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

Joined: Nov 15, 2008
Posts: 10
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Many to Many Relation Error Driving Me Mad