aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate - Cascading problems using ManyToOne association Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - Cascading problems using ManyToOne association" Watch "Hibernate - Cascading problems using ManyToOne association" New topic
Author

Hibernate - Cascading problems using ManyToOne association

Niklas Johansson
Greenhorn

Joined: Apr 20, 2009
Posts: 4
Hello,

I am working with Hibernate trying to get ManyToOne working. But problems of course since I am here...

I am working with two classes (Tables)
1. Users
2. Incident

The users are unique and the identifier is "email". One user can have multiple incidents but one incident can only have one user. Though it is not a bi-directional relation, incident knows about the user but user doesn't know about the incident.

I am not getting any exceptions, the problem I am having is that only Incident table is updated and not the user table. Also, an extra column in the incident table is created named "USERS_EMAIL". I understand where I define this, but I didn't fully understand Hibernates instructions, perhaps handling it incorrect.

Shouldn't the cascading take care of updating my Users table automatically? Or do I have to explicitly persist my Users object? If that is the case, is there any point using @JoinColumn or at all defining the ManyToOne relation?

Any help would be most appreciated, especially as this seems to be the last big threshold for me applying Hibernate for real. Thanks in advance!

Show SQL:



My Entity classes:

Users:



And Incident



And from this class I am trying to save the data. The parameter data is coming in correctly, verified by System.out.println...



Best Regards,
Niklas

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

We have an ORM forum for Hibernate questions.

Moving this to that forum

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate - Cascading problems using ManyToOne association