[jboss-user] [JBoss Seam] - Re: Domain model duplicates validation

fernando_jmt do-not-reply at jboss.com
Sun May 27 02:52:21 EDT 2007


I don't know what exactly you mean with "without mapping that to the database", but anyway I have solved something similar as follows:


  | @Entity
  | @Table(name = "person", uniqueConstraints = @UniqueConstraint(columnNames = {"firstname", "lastname"}))
  | public class Person {
  |     @Id
  |     private Long id;
  |     @Column(name = "firstname")
  |     private String firstName;
  |     @Column(name = "lastname")
  |     private String lastName;
  |     private String address;
  | 
  |     public Long getId() {
  |         return id;
  |     }
  | 
  |     public void setId(Long id) {
  |         this.id = id;
  |     }
  | 
  |     public String getFirstName() {
  |         return firstName;
  |     }
  | 
  |     public void setFirstName(String firstName) {
  |         this.firstName = firstName;
  |     }
  | 
  |     public String getLastName() {
  |         return lastName;
  |     }
  | 
  |     public void setLastName(String lastName) {
  |         this.lastName = lastName;
  |     }
  | 
  |     public String getAddress() {
  |         return address;
  |     }
  | 
  |     public void setAddress(String address) {
  |         this.address = address;
  |     }
  | }
  | 
  | 

With above, the validation is done in database layer, but it is caught by JPA  and it throws a javax.persistence.EntityExistsException. It works for me in the sense I don't have to write any special login in a Session Bean to validate this.

HTH.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048884#4048884

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4048884



More information about the jboss-user mailing list