• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBeat Question

 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please look the following question:

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

Could anyone tell me the correct Answere.
I think, The Answere is a,b,c.
But, The correct Answrere the javabeat is giving is a,b,d
Another One:
Which of the following are true about composite primary keys.

a)The primary key class must be Serilizable
b)The application must not change the value of the primary key.
c)Properties of primary key class must be public or protected.
d)Primary key class must be public
e) All the above

I think the Answere is b.
But correct the Answere is f.

Could anybody explain these?
[ July 22, 2008: Message edited by: krishna bulusu ]
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
see at the end of 2.1 jsr-220 persistence paragraph:

Instance variables must be private, protected or package visibility.

For what concerns the primary key, give a look at 2.1.4 paragraph: it says that:

The primary key class must be public and must have a public no-arg constructor.
If property-based access is used, the properties of the primary key class must be public or protected.
The primary key class must be serializable.
...
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, for me it is working fine if I make the instance variable public in the Entity.
And also, the example given in the Manning EJB 3.0 in action, the composite primary class didn't implement the Serializable interface.
Is this all depends upon how the App server actually implement the rules?
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
this is an old issue that sometimes comes back.
Here we are speaking of Sun Microsystems specifications and not implementation of them: if you want to build a portable enterprise application, you should follow the specs, and not try-and-error with a specific application server.

However, the specs say that the property fields must be private, protected or package visibility, but don't say what should happen if you set them public. Probably, your app server decided to accept public modifiers for instance variables.
Finally, for what concerns making your primary key serializable, I don't know Manning book, but it might be a mistake.
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Krishna,

primary key classes are the ones you use with @idclass tag, I hope you are not confusing them with @embeddable classes beacause there is no such requirement (serialisability) for them.

regarding the other one, entities instance vairiables should not be public, they follow javabeans standard.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic