Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock question about field visibility of Entities

 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In the JavaBeat'site, there's a question about entities and I'm not sure of the answer:

6)Which of the following statements are correct?

a)Entities supports inheritance
b)Abstract class and concrete classes can be entities.
c)Intance variables of an entity class can be public
d)Instance variables of an entity class must be private,protected or package visibility

The answer is a, b and d.

I agree with a and b.
But I can't find anywhere in the spec any restriction about the visibility of the fields.
So, for me, c is OK and d is false...

Any idea ?

Thanks,

Beno�t
 
Alex Kikhtenko
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Beno�t.

Here is the quote from the JPA specification (page 16, "2.1 Requirements on the Entity Class"):

"The persistent state of an entity is represented by instance variables, which may correspond to Java-Beans properties. An instance variable may be directly accessed only from within the methods of the entity by the entity instance itself. Instance variables must not be accessed by clients of the entity. The state of the entity is available to clients only through the entity�s accessor methods (getter/setter methods) or other business methods. Instance variables must be private, protected, or package visibility."
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Alex.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic