I created an EJB Session facade in my Netbeans 7 for saving my entity. I have a manytoone mapping between my Insurance and RatePlan Class.
public class Insurance{
@ManyToOne(optional=false)
@JoinColumn(name="PLAN_ID")
private RatePlan plan;
}
public class RatePlan{
@OneToMany(mappedBy="plan")
private Set<Insurance> insuranceItems;
}
When I tried saving in my database using my EJB Session Bean, I am encountering below error.
Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
What I did was to turn off my Bean validation in my Persistence.xml file. I would like to know what Bean validation error has occurred but I dont know how or where to find it or how to configure and catch it.
My EJB facade is a simple class like tis.
public class InsuranceFacade{
public void saveInsurance(Insurance insurance){
em.persist(insurance);
}
}
Any hints?
The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean. Constraints can be built in or user defined. User-defined constraints are called custom constraints.
The @NotNull annotation is defined in the Bean Validation specification. This means its usage isn't limited only to the entities. On the contrary, we can use @NotNull on any other bean as well. As we can see, in this case, our system threw javax.
Very basically, Bean Validation works by defining constraints to the fields of a class by annotating them with certain annotations.
The Bean Validation API provides a set of built-in constraints and an interface that enables you to declare custom constraints. This is accomplished by creating constraint annotations and declaring an annotation on a bean type, field, or property.
I would like to know what Bean validation error has occurred but I dont know how or where to find it or how to configure and catch it.
To know what specific constraint violations have occurred, you could just inspect the exception caught. ConstraintViolationException.getConstraintViolations() returns a Set of ConstraintViolations which you can iterate and inspect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With