java - How to validate model with eclipselink jpa -


i hava model, , need validate model eclipselink jpa , add anotation @notempty validate name if empty, when save/persist model, validate not work

  @entity     public class role {          @id         private string id;         @notempty         private string name;          public string getid() {             return id;         }          public void setid(string id) {             this.id = id;         }          public string getname() {             return name;         }          public void setname(string name) {             this.name = name;         }      } 

my jpa configuration xml this

<?xml version="1.0" encoding="utf-8"?>  <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"              xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"              xsi:schemalocation="http://java.sun.com/xml/ns/persistence    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">      <persistence-unit name="eclipselink_jpa" transaction-type="resource_local">         <provider>org.eclipse.persistence.jpa.persistenceprovider</provider>         <class>app.test.model.role</class>          <properties>              <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test"/>             <property name="javax.persistence.jdbc.user" value="root"/>             <property name="javax.persistence.jdbc.password" value=""/>             <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver"/>           </properties>     </persistence-unit> </persistence> 

the jpa api (which eclipselink implements) nothing bean validation api. utilise bean validation api need bean validation api jar (javax.validation), implementation of api (apache bval, hibernate validator, etc) in classpath. thing jpa provides auto-enable validation per this link, default "auto" nothing required that


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -