my dog learned polymorphism
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Entity and set/get methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Entity and set/get methods" Watch "Entity and set/get methods" New topic

Entity and set/get methods

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918


I have a Entity which has a non-transitive property, for this property I have no set/get. If I persist this in the database I get the value for the field with no geter. That means, the entity manager does not care of setter or getter, it just "grab" the value .
the next code snippet show the entity :

After this entity is persisted in the db I have for the stuff variable the value 10. Strange because I don't have a get for.

My question is : why is doing the the jpa container this ? Is this specified in the specifications ?


Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Because you did put the id annotation on the getter the persistence provider assumes you want to use property based persistence.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Thanks for your answer

I already spot this i the specification (2.2 Persistent Fields and Properties)

The persistent state of an entity is accessed by the persistence provider runtime[1] either via JavaBeans style property accessors (“property access”) or via instance variables (“field access”). Whether persistent properties or persistent fields or a combination of the two is used for the provider’s access to a given class or entity hierarchy is determined as described in Section 2.3, “Access Type”.

I agree. Here's the link:
subject: Entity and set/get methods
It's not a secret anymore!