Im confused with the JPA manytoone relationship, i have a class 'judgement' which has many 'judges', when i tried to store a judgement instance into postgres db, it threw error message as:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.dyihi.evaluation.model.Judgement.judge -> com.dyihi.evaluation.model.User
the judgement class:
@Entity
@Table(name = "JUDGEMENTS")
public class Judgement implements Serializable, Cloneable {
/**
*
*/
private static final long serialVersionUID = -7049957706738879274L;
@ManyToOne(cascade = { CascadeType.REFRESH, CascadeType.DETACH})
@JoinColumn(name = "user_id")
private User judge;
and my service class:
public Long store(Judgement judgement) throws RepositoryException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = _emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
em.persist(judgement);
tx.commit();
return judgement.getId();
}
finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
if (em != null) {
em.close();
em = null;
}
}
}
and in my db i have tables Judgement and User, do i need to create a table as Judgement_User for the ManyToOne relationship?