JPA 2.0 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/17 23:01 UTC
Read the original article Hit count: 185

Filed under:
|
|

hello i am having 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 keyof EXAM is missing because it isnt persisted...

Is there any way to define the order?Or i should set null the list ,persist and then set the list again ? thanks:)

© Stack Overflow or respective owner

Related posts about jpa

Related posts about persist