[jboss-cvs] jboss-seam/examples/contactlist/src/org/jboss/seam/example/crud ...

Gavin King gavin.king at jboss.com
Thu Oct 5 16:42:14 EDT 2006


  User: gavin   
  Date: 06/10/05 16:42:14

  Modified:    examples/contactlist/src/org/jboss/seam/example/crud  
                        Contact.java
  Added:       examples/contactlist/src/org/jboss/seam/example/crud  
                        Comment.java
  Log:
  example of association handling
  
  Revision  Changes    Path
  1.3       +14 -0     jboss-seam/examples/contactlist/src/org/jboss/seam/example/crud/Contact.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Contact.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/contactlist/src/org/jboss/seam/example/crud/Contact.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- Contact.java	28 Sep 2006 01:30:28 -0000	1.2
  +++ Contact.java	5 Oct 2006 20:42:14 -0000	1.3
  @@ -1,8 +1,14 @@
   package org.jboss.seam.example.crud;
   
  +import java.util.ArrayList;
  +import java.util.List;
  +
  +import javax.persistence.CascadeType;
   import javax.persistence.Entity;
   import javax.persistence.GeneratedValue;
   import javax.persistence.Id;
  +import javax.persistence.OneToMany;
  +import javax.persistence.OrderBy;
   
   import org.hibernate.validator.Length;
   
  @@ -33,6 +39,10 @@
      @Length(max=20)
      private String cellPhone;
      
  +   @OneToMany(mappedBy="contact", cascade=CascadeType.REMOVE)
  +   @OrderBy("created")
  +   private List<Comment> comments = new ArrayList<Comment>();
  +   
      public String getAddress()
      {
         return address;
  @@ -121,4 +131,8 @@
      {
         this.id = id;
      }
  +   public List<Comment> getComments()
  +   {
  +      return comments;
  +   }
   }
  
  
  
  1.1      date: 2006/10/05 20:42:14;  author: gavin;  state: Exp;jboss-seam/examples/contactlist/src/org/jboss/seam/example/crud/Comment.java
  
  Index: Comment.java
  ===================================================================
  package org.jboss.seam.example.crud;
  
  import java.util.Date;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.ManyToOne;
  
  import org.hibernate.validator.Length;
  import org.hibernate.validator.NotNull;
  
  @Entity
  public class Comment
  {
     @Id @GeneratedValue 
     private Long id;
     
     @NotNull @ManyToOne
     private Contact contact;
     
     @NotNull @Length(max=1500)
     private String text;
     
     @NotNull
     private Date created = new Date();
  
     public Contact getContact()
     {
        return contact;
     }
  
     public void setContact(Contact contact)
     {
        this.contact = contact;
        contact.getComments().add(this);
     }
  
     public Long getId()
     {
        return id;
     }
  
     public String getText()
     {
        return text;
     }
  
     public void setText(String text)
     {
        this.text = text;
     }
  
     public Date getCreated()
     {
        return created;
     }  
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list