hibernate validation doesn't happen on persist in database
The configuration properties you are referencing apply to JPA. If you are using the JPA API it should work. It looks like that you are using the native Hibernate ORM Session API. You need to use the EntityManager
API.
You need to use Hibernate validator.Here the maven artifact
<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><version>5.1.3.Final</version>
Here the getting start documentation.
http://hibernate.org/validator/documentation/getting-started/
If you're using JPA, you need to add the following EntityManager listeners:
<event type="pre-update"> <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/></event><event type="pre-insert"> <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/></event><event type="pre-delete"> <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/></event>
And also add the following property:
<property name="javax.persistence.validation.mode"> ddl, callback</property>
If you are using Hibernate specific configuration, with hibernate.cfg.xml
, then the configs become:
<event type="pre-update"> <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/></event><event type="pre-insert"> <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/></event><event type="pre-delete"> <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/></event>