users@glassfish.java.net

RE: Persistence, ignoring a class field

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 8 Jan 2007 11:08:08 -0500

Hello Kenneth,
    All you need is the @Transient annotation. In the case of field access your code would appear like:
@Entity
class StaffMember{
    @Transient
    private Credentials credentials; //<-- I want to ignore this.

    public Credentials getCredentials(){
       //impl
    }
    public void setCredentials(Credentials value){
      //impl
    }
    
}

--Gordon


  -----Original Message-----
  From: Kenneth Clark [mailto:kenneth_at_rabiddog.co.za]
  Sent: Monday, January 08, 2007 11:02 AM
  To: users_at_glassfish.dev.java.net
  Subject: Persistence, ignoring a class field


  Hi all

  I have search high and low and cannot figure this out.
  I have to classes, one for a StaffMember and another one containing the credentials for the staff member. The reason I decided to separate them is because the staff member details are stored in an SQL DB and the user details are stored inside and LDAP server.

  I would like to map the staff member as an entity and tell the entity to ignore the credentials.

  Now I see no "Ignore" or anything similar annotation.

  I have accessors for the credentials prefixed with get and set. I assume the annotation processing engine looks at the get and set prefixes to derive the fields/properties it needs to persist. Would prefixing the accessors with something other than get or set make the engine ignore the methods? Is there a less contrived way of doing this?

  @Entity
  class StaffMember{
      private Credentials credentials; //<-- I want to ignore this.

      public Credentials getCredentials(){
         //impl
      }
      public void setCredentials(Credentials value){
        //impl
      }
      
  }


  Thanks for all your help
  Kenneth