I have two entities: EXAM and EXAM_NORMAL.
EXAM
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String name;
private String codeName;
@Enumerated(EnumType.STRING)
private ExamType examType;
@ManyToOne
private Category category;
@OneToMany(mappedBy="id",cascade=CascadeType.PERSIST)
@OrderBy("id")
private List<Exam_Normal> exam_Normal;
EXAM_NORMAL
@Id
private Long item;
@Id
@ManyToOne
private Exam id;
@Enumerated(EnumType.STRING)
private Gender gender;
private Integer age_month_from;
private Integer age_month_to;
The problem is that if I put a list of EXAM_NORMAL at an EXAM class if I try to persist(EXAM) I get an error because it tries to persist EXAM_NORMAL first but it cant because the primary key of EXAM is missing because it isn't persisted...
Is there any way to define the order? Or should I set null
the list, persist and then set the list again?
thanks:)