JPA 2.0 EclipseLink Check for unique
Posted
by Parhs
on Stack Overflow
See other posts from Stack Overflow
or by Parhs
Published on 2010-04-14T23:23:48Z
Indexed on
2010/04/15
0:13 UTC
Read the original article
Hit count: 620
Hello... I have a collumn as unique=true.. in Exam class.... I found that because transactions are commited automaticaly so to force the commit i use em.commit()
However i would like to know how to check if it is unique.Running a query isnt a solution because it may be an instert after checking because of the concurency....
Which is the best way to check for uniqness?
List<Exam_Normal> exam_normals = exam.getExam_Normal();
exam.setExam_Normal(null);
try {
em.persist(exam);
em.flush();
Long i = 0L;
if (exam_normals != null) {
for (Exam_Normal e_n : exam_normals) {
i++;
e_n.setItem(i);
e_n.setId(exam);
em.persist(e_n);
}
}
} catch (Exception e) {
System.out.print("sfalma--");
}
}
d
© Stack Overflow or respective owner