Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Persistent field and Persistent properties - difference

421 views
Skip to first unread message

gk

unread,
Oct 12, 2010, 7:38:13 AM10/12/10
to
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 ?

Lew

unread,
Oct 12, 2010, 8:52:16 AM10/12/10
to

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

unread,
Oct 12, 2010, 8:54:49 AM10/12/10
to
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

gk

unread,
Oct 12, 2010, 12:46:58 PM10/12/10
to

> 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 ?


Tom Anderson

unread,
Oct 12, 2010, 2:32:36 PM10/12/10
to

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

unread,
Oct 12, 2010, 2:33:58 PM10/12/10
to

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.

Jean-Baptiste Nizet

unread,
Oct 12, 2010, 4:43:19 PM10/12/10
to
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.

Tom Anderson

unread,
Oct 12, 2010, 5:43:29 PM10/12/10
to
On Tue, 12 Oct 2010, Jean-Baptiste Nizet wrote:

> Le 12/10/2010 20:32, Tom Anderson a ?crit :

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

0 new messages