users@glassfish.java.net

RE: Re: Persistence, ignoring a class field

From: Jason Lee <lee_at_iecokc.com>
Date: Mon, 8 Jan 2007 11:07:44 -0600

Funny note on how the brain works if you're not paying close attention.
After much head scratching, pain, and agony, we learned how "transient"
!= "@Transient". ;)
 
-----
Jason Lee, SCJP
Programmer/Analyst
http://www.iec-okc.com <http://www.iec-okc.com/>
 


  _____

        From: Kenneth Clark [mailto:kenneth_at_rabiddog.co.za]
        Sent: Monday, January 08, 2007 10:15 AM
        To: users_at_glassfish.dev.java.net
        Subject: Re: Persistence, ignoring a class field
        
        
        Thanks very much, after reading your comments I check the EJB
persistence spec:
        
        "If the entity has field-based access, the persistence provider
runtime accesses instance variables
        directly. All non-transient instance variables that are not
annotated with the Transient
        annotation are persistent. When field-based access is used, the
object/relational mapping annotations
        for the entity class annotate the instance variables."
        
        Thanks again for the pointer, next time I will make sure I read
the docs properly :D
        
        Cheers
        Kenenth
        
        Gordon Yorke wrote:

                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
                        

                
  _____


                No virus found in this incoming message.
                Checked by AVG Free Edition.
                Version: 7.5.432 / Virus Database: 268.16.7/619 -
Release Date: 07/01/2007 18:29