I have a column like unique = true .. in the exam class .... I found that since transactions are automatic, so for forced use I use em.commit ()
However, I would like to know how to check if it is unique. Querying an exception is not a solution, because it may be an attempt after verification due to consistency ....
What is the best way to check 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
source
share