Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Cascading problems using ManyToOne association

 
Niklas Johansson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have an ORM forum for Hibernate questions.

Moving this to that forum

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic