Error trying to persist entities in JPA
Bean Validation constraint (s) violated while executing Automatic Bean Validation on callback event: 'prePersist'. Please refer to embedded ConstraintViolations for details.
Error trying to persist entities in JPA
Bean Validation constraint (s) violated while executing Automatic Bean Validation on callback event: 'prePersist'. Please refer to embedded ConstraintViolations for details.
This error occurs when the constraints defined in the entity that are persiste
are violated. You must validate that the values that are NotNull
are not saved with null
and any other defined restriction.
You could use the following code to clarify a little more the error about what has been the problem.
I use the AbstracFacade
that is generated in NetBeans, and within this file, in the methods create
and edit
, define them as follows:
public void create(T entity) {
try {
getEntityManager().persist(entity);
} catch (ConstraintViolationException e) {
// Aqui tira los errores de constraint
for (ConstraintViolation actual : e.getConstraintViolations()) {
System.out.println(actual.toString());
}
}
}
public T edit(T entity) {
try {
return getEntityManager().merge(entity);
} catch (ConstraintViolationException e) {
// Aqui tira los errores de constraint
for (ConstraintViolation actual : e.getConstraintViolations()) {
System.out.println(actual.toString());
}
}
return null;
}
Thus, at the time that the persistence error occurs, in the log
it will show you more detail of the error.
I have exactly the same error. I am migrating a java application project to a web application with maven. It all has to do with the persistence.xml file.
In Validation Strategy you must enter None.