Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.contact; import java.io.Serializable; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table; import javax.persistence.Transient; import javax.persistence.Version; import javax.validation.constraints.Size; import org.hibernate.annotations.Type; import org.hibernate.validator.constraints.NotEmpty; import org.joda.time.DateTime; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; /** * * @author giuliano */ @Entity @Table(name = "Contact") public class Contact implements Serializable { private static final long serialVersionUID = 1L; private Long id; private int version; private String firstName; private String lastName; private DateTime birthDate; private String description; private byte[] photo; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Version @Column(name = "VERSION") public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } @NotEmpty(message = "{validation.firstname.NotEmpty.message}") @Size(min = 3, max = 60, message = "{validation.firstname.Size.message}") @Column(name = "FIRST_NAME") public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } @NotEmpty(message = "{validation.lastname.NotEmpty.message}") @Size(min = 1, max = 40, message = "{validation.lastname.Size.message}") @Column(name = "LAST_NAME") public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } @Column(name = "BIRTH_DATE") @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") @DateTimeFormat(iso = ISO.DATE) public DateTime getBirthDate() { return birthDate; } public void setBirthDate(DateTime birthDate) { this.birthDate = birthDate; } @Column(name = "DESCRIPTION") public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @Basic(fetch = FetchType.LAZY) @Lob @Column(name = "PHOTO") public byte[] getPhoto() { return photo; } public void setPhoto(byte[] photo) { this.photo = photo; } @Transient public String getBirthDateString() { String birthDateString = ""; if (birthDate != null) birthDateString = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd").print(birthDate); return birthDateString; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Contact)) { return false; } Contact other = (Contact) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "Contact - Id: " + id + ", First name: " + firstName + ", Last name: " + lastName + ", BirthDate: " + birthDate + ", Description: " + description; } }