Persistent field and Persistent properties - difference

Discussion in 'Java' started by gk, Oct 12, 2010.

  1. gk

    gk Guest

    In JPA Entity classes , I don't understand what is a persistent field
    and what is a persistent property ?


    I have the following understanding as below

    If the Entiry class has NO getter/setter then we call the instance
    variable as persistent field
    For example,
    public class Contact implements Serializable{
    protected String firstName;
    // firstName is the persistent field.
    // there is no getter/setter for firstName
    .........................
    ............................



    BUT

    If the Entity class has getter/setter then we call the instance
    variable as persistent property
    For example,
    public class Contact implements Serializable{
    protected String firstName; // firstName is the persistent
    property.
    void setfirstName(String fname){firstName=fname;}
    String setfirstName(String fname){return firstName;}
    .........................
    ............................


    Could you please let me know whether I have understood the terminology
    persistent field and persistent property correctly. If not , please
    let me know where is the difference between them ?
     
    gk, Oct 12, 2010
    #1
    1. Advertising

  2. gk

    Lew Guest

    On 10/12/2010 07:38 AM, gk wrote:
    > In JPA Entity classes , I don't understand what is a persistent field
    > and what is a persistent property ?
    >
    >
    > I have the following understanding as below
    >
    > If the Entiry class has NO getter/setter then we call the instance
    > variable as persistent field
    > For example,
    > public class Contact implements Serializable{
    > protected String firstName;
    > // firstName is the persistent field.
    > // there is no getter/setter for firstName
    > .........................
    > ...........................
    >
    >
    >
    > BUT
    >
    > If the Entity class has getter/setter then we call the instance
    > variable as persistent property
    > For example,
    > public class Contact implements Serializable{
    > protected String firstName; // firstName is the persistent
    > property.
    > void setfirstName(String fname){firstName=fname;}
    > String setfirstName(String fname){return firstName;}
    > .........................
    > ...........................
    >
    >
    > Could you please let me know whether I have understood the terminology
    > persistent field and persistent property correctly. If not , please
    > let me know where is the difference between them ?


    In this case they're synonymous.

    Strictly speaking, a "field" is a member variable and a "property" is a
    publicly accessible attribute, usually accessed in Java via get.../set...
    methods, that behaves to the world like a field but might actually be
    implemented differently.

    That's a rather loose definition but works all right in practice.

    --
    Lew
     
    Lew, Oct 12, 2010
    #2
    1. Advertising

  3. gk

    Lew Guest

    gk wrote:
    >> In JPA Entity classes , I don't understand what is a persistent field
    >> and what is a persistent property ?
    >>
    >>
    >> I have the following understanding as below
    >>
    >> If the Entiry class has NO getter/setter then we call the instance
    >> ...
    >> BUT
    >> ...
    >> Could you please let me know whether I have understood the terminology
    >> persistent field and persistent property correctly. If not , please
    >> let me know where is the difference between them ?


    Lew wrote:
    > In this case they're synonymous.
    >
    > Strictly speaking, a "field" is a member variable and a "property" is a
    > publicly accessible attribute, usually accessed in Java via
    > get.../set... methods, that behaves to the world like a field but might
    > actually be implemented differently.
    >
    > That's a rather loose definition but works all right in practice.


    Another point - I don't think you can use JPA without getters and setters for
    the entity fields.

    --
    Lew
     
    Lew, Oct 12, 2010
    #3
  4. gk

    gk Guest


    > Another point - I don't think you can use JPA without getters and setters for
    > the entity fields.


    Thanks for the post.

    see this text below as to why I asked the differences between the two
    wording...

    The persistent state of an entity is represented either by its
    *persistent fields or persistent properties*.

    "persistent fields" vs "persistent properties" ... how they differ ?
     
    gk, Oct 12, 2010
    #4
  5. gk

    Tom Anderson Guest

    On Tue, 12 Oct 2010, Lew wrote:

    > gk wrote:
    >>> In JPA Entity classes , I don't understand what is a persistent field
    >>> and what is a persistent property ?
    >>>
    >>> I have the following understanding as below
    >>>
    >>> If the Entiry class has NO getter/setter then we call the instance
    >>> ...
    >>> BUT
    >>> ...
    >>> Could you please let me know whether I have understood the terminology
    >>> persistent field and persistent property correctly. If not , please
    >>> let me know where is the difference between them ?

    >
    > Lew wrote:
    >
    >> In this case they're synonymous.
    >>
    >> Strictly speaking, a "field" is a member variable and a "property" is a
    >> publicly accessible attribute, usually accessed in Java via
    >> get.../set... methods, that behaves to the world like a field but might
    >> actually be implemented differently.
    >>
    >> That's a rather loose definition but works all right in practice.

    >
    > Another point - I don't think you can use JPA without getters and setters for
    > the entity fields.


    You can. You annotate the fields, and the provider accesses them with
    reflection or some other mechanism. Some (including myself) consider it
    preferable to access via the accessors, because it means you don't have to
    have accessors where it's not appropriate (see discussions on getters,
    setters and object orientation passim), and you're free to do clever stuff
    in them when it is.

    Thinking about it, i don't know if this is something the spec guarantees,
    or something that implementations happen to support. I'll check.

    tom

    --
    Caps lock is like cruise control for cool.
     
    Tom Anderson, Oct 12, 2010
    #5
  6. gk

    Tom Anderson Guest

    On Tue, 12 Oct 2010, gk wrote:

    >> Another point - I don't think you can use JPA without getters and
    >> setters for the entity fields.

    >
    > Thanks for the post.
    >
    > see this text below as to why I asked the differences between the two
    > wording...
    >
    > The persistent state of an entity is represented either by its
    > *persistent fields or persistent properties*.
    >
    > "persistent fields" vs "persistent properties" ... how they differ ?


    This looks like unnecessary and unhelpful splitting of hairs to me. After
    all, it is *only* fields that are persisted, because fields are the only
    place state lives. The distinction, if you must draw one, between fields
    and properties is about how they're accessed, or even how they're thought
    about.

    tom

    --
    Caps lock is like cruise control for cool.
     
    Tom Anderson, Oct 12, 2010
    #6
  7. Le 12/10/2010 20:32, Tom Anderson a écrit :
    >>

    >
    > You can. You annotate the fields, and the provider accesses them with
    > reflection or some other mechanism. Some (including myself) consider it
    > preferable to access via the accessors, because it means you don't have
    > to have accessors where it's not appropriate (see discussions on
    > getters, setters and object orientation passim), and you're free to do
    > clever stuff in them when it is.
    >
    > Thinking about it, i don't know if this is something the spec
    > guarantees, or something that implementations happen to support. I'll
    > check.
    >


    It's guaranteed by the spec :

    2.1.1 Persistent Fields and Properties
    The persistent state of an entity is accessed by the persistence
    provider runtime[1] either via JavaBeans
    style property accessors or via instance variables. A single access type
    (field or property access) applies
    to an entity hierarchy. When annotations are used, the placement of the
    mapping annotations on either
    the persistent fields or persistent properties of the entity class
    specifies the access type as being either
    field- or property-based access respectively.


    JB.
     
    Jean-Baptiste Nizet, Oct 12, 2010
    #7
  8. gk

    Tom Anderson Guest

    On Tue, 12 Oct 2010, Jean-Baptiste Nizet wrote:

    > Le 12/10/2010 20:32, Tom Anderson a ?crit :
    >
    >> You can. You annotate the fields, and the provider accesses them with
    >> reflection or some other mechanism. Some (including myself) consider it
    >> preferable to access via the accessors, because it means you don't have
    >> to have accessors where it's not appropriate (see discussions on
    >> getters, setters and object orientation passim), and you're free to do
    >> clever stuff in them when it is.
    >>
    >> Thinking about it, i don't know if this is something the spec
    >> guarantees, or something that implementations happen to support. I'll
    >> check.

    >
    > It's guaranteed by the spec :
    >
    > 2.1.1 Persistent Fields and Properties
    > The persistent state of an entity is accessed by the persistence
    > provider runtime[1] either via JavaBeans style property accessors or via
    > instance variables. A single access type (field or property access)
    > applies to an entity hierarchy. When annotations are used, the placement
    > of the mapping annotations on either the persistent fields or persistent
    > properties of the entity class specifies the access type as being either
    > field- or property-based access respectively.


    Je suis redevable a votre bienveillance. And needless to say, i am no
    longer going to check!

    tom

    --
    there is never a wrong time to have your bullets passing further into
    someone's face -- D
     
    Tom Anderson, Oct 12, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,233
  2. FabSW

    roleprovider persistent field

    FabSW, Nov 8, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    139
    FabSW
    Nov 8, 2006
  3. SilentCry

    proper way to initialize/use persistent properties

    SilentCry, May 20, 2009, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    740
    SilentCry
    May 20, 2009
  4. Sound
    Replies:
    2
    Views:
    453
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    426
Loading...

Share This Page