1 package org.hibernate.validator.test; 3 4 import javax.persistence.Entity; 5 import javax.persistence.Id; 6 import javax.persistence.Transient; 7 8 import org.hibernate.validator.AssertTrue; 9 import org.hibernate.validator.Length; 10 import org.hibernate.validator.Min; 11 import org.hibernate.validator.NotNull; 12 import org.hibernate.validator.Pattern; 13 import org.hibernate.validator.Range; 14 15 18 @Entity 19 public class Address { 20 private String line1; 21 private String line2; 22 private String zip; 23 private String state; 24 private String country; 25 private long id; 26 27 @Length(max=20) 28 @NotNull 29 public String getCountry() { 30 return country; 31 } 32 33 public void setCountry(String country) { 34 this.country = country; 35 } 36 37 @NotNull 38 public String getLine1() { 39 return line1; 40 } 41 42 public void setLine1(String line1) { 43 this.line1 = line1; 44 } 45 46 public String getLine2() { 47 return line2; 48 } 49 50 public void setLine2(String line2) { 51 this.line2 = line2; 52 } 53 54 @Length(max=3) @NotNull 55 public String getState() { 56 return state; 57 } 58 59 public void setState(String state) { 60 this.state = state; 61 } 62 63 @Length(max=5, message="{long}") 64 @Pattern(regex="[0-9]+") 65 @NotNull 66 public String getZip() { 67 return zip; 68 } 69 70 public void setZip(String zip) { 71 this.zip = zip; 72 } 73 74 @AssertTrue 75 @Transient 76 public boolean isValid() { 77 return true; 78 } 79 80 @Id @Min(1) 81 @Range(max=2000) 82 public long getId() { 83 return id; 84 } 85 86 public void setId(long id) { 87 this.id = id; 88 } 89 90 } 91 | Popular Tags |