Reputation: 82
I read a lot of topic and forum about @OneToMany but unfortunatelly any of this couldn't help.
For example we have Entities like these:
@Entity
@Table(name = "MANAGER")
public class Manager{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "MAN_ID")
private long id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "MAN_ID", updatable=true)
private Set<Workers> workers;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "MAN_ID", updatable=true)
private Set<Helpers> helpers;
...
}
@Entity
@Table(name = "WORKERS")
public class Workers{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private long id;
...
}
@Entity
@Table(name = "HELPERS")
public class Helpers{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private long id;
...
}
And now im trying to save first time Manager object (with not empty both sets)
Session session = getSession();
Transaction tx = session.beginTransaction();
session.save(holder);
tx.commit();
In return i see how hibernate tries to do inserts, but there is not update for workers and helpers. When im getting Manager back from DB, both lists are empty (null). What am i missing here?
Upvotes: 0
Views: 436
Reputation: 82
It looks like i was missing nullable
@JoinColumn(name = "MAN_ID", nullable = false)
Upvotes: 2