• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate - Cascading problems using ManyToOne association

Niklas Johansson
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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:


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,

Mark Spritzler
Posts: 17309
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

Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!