Posts

Showing posts from November, 2013

Bean Validation : Hibernate Validator framework

Bean Validation with Hibernate Validator framework JSR 303 This JSR will define a meta-data model and API for JavaBean TM validation based on annotations, with overrides and extended meta-data through the use of XML validation descriptors. http://jcp.org/en/jsr/detail?id=309 JSR 349 Bean Validation standardizes constraint definition, declaration and validation for the Java platform. For more information on Bean Validation and how to participate, check out http://beanvalidation.org . http://jcp.org/en/jsr/detail?id=349  Hibernate Validator Hibernate Validator 5.x is the reference implementation for JSR 349 - Bean Validation 1.1 of which Red Hat is the specification lead. http://www.hibernate.org/subprojects/validator.html Sample Implementation. In the sample implementation, we have a class User.java with validation annotations. A test class to validate the object and to print the error messages at the console. The code is completely self explanatory. User.java

Hibernate Annotations - OnetoOne Mapping

Hibernate Annotations JPA 1   One to One Mapping   Class Employee.java package com.domain; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; @Entity @Table(name = "employeeaddress") public class EmployeeAddress implements java.io.Serializable {     private static final long serialVersionUID = 1L;     // Fields     private Integer employeeid;     private String address;     private Employee employee;     // Constructors     /** default constructor */     public EmployeeAddress() {     }     /** minimal constructor */     public EmployeeAddress(Integer employeeid) {         this.employeeid = employeeid;     }     /** full constructor */     public EmployeeAddress(Integer employeeid, String address) {         this.employeeid = employeeid;         this.address = address;