This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate inserting man-to-one fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate inserting man-to-one fails" Watch "Hibernate inserting man-to-one fails" New topic
Author

Hibernate inserting man-to-one fails

Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
I have a Player object that holds on to an Address object and use a many-to-one mapping as follows:



when I save my Player object, I want it to save the address object, hence the cascade="all" in the Player mapping. However the SQL that it generates is:



Why is it trying to do an update on the address object instead of an insert? Is there something I need to correct in the mapping?

Thanks for the help
Brian
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
Found the answer in another post, didn't look long enough. The unsave-value I had on my class definitions was using null, which was not correct since my ids were ints. I changed to unsave-value="0" and it worked!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate inserting man-to-one fails
 
Similar Threads
Mapping Exception
How can I map hibernate component subclasses?
Hibernate Issue
bidirectional one to many mapping issues
Hibernte will delete rows from a table, but it won't insert rows