I'm unable to set up a bidirectional one-to-many relationship.
Code:
public class Person() {
...
@OneToMany(mappedBy="person")
public Set<Invoice> getInvoices() {
return invoices;
}
}
Code:
public class Invoice() {
...
@ManyToOne
@JoinColumn(name="fk")
public Person getPerson() {
return person;
}
}
I use this method to save the
person object. (eg:
saveOrUpdate(new Person(...));Code:
protected void saveOrUpdate(Object obj) {
try {
startOperation();
session.saveOrUpdate(obj);
tx.commit();
} catch (HibernateException e) {
HibernateFactory.rollback(tx);
handleException(e);
} finally {
HibernateFactory.close(session);
}
}
I tried many variants on this, but I always get a unidirectional relationship instead of a bidirectional relationship.
Here are some examples of variants I tried, but without result.
Code:
@ManyToOne(cascade=CascadeType.PERSIST)
@JoinColumn(name="fk", insertable=false, updatable=false)
...
@OneToMany (targetEntity=Invoice.class, mappedBy="invoice", cascade=CascadeType.ALL)
...
Why can I never get a bidirectional relationship???