How to persist in order

Posted by parhs on Stack Overflow See other posts from Stack Overflow or by parhs
Published on 2010-03-17T01:10:49Z Indexed on 2010/03/18 15:41 UTC
Read the original article Hit count: 146

Filed under:
|
|
|

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:)

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa