File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejbCreate method for Entity bean

 
Jaroslav Jarni
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting ready for the exam and I have a question in regards to the question from HFEJB, chapter�s 6 mock exam, question number 5 that asks:

Which are legal declarations for a CMP bean�s ejbCreate methods? Now it is entity bean we are talking about here.

That method ( ejbCreate() ) under the given circumstances (we are talking Entity beans here) should return the type of primary key. And the spec says

10.6.13 page 197

The primary key type must be a legal Value Type in RMI-IIOP.

So, is this a legal declaration?

public int ejbCreate() throws javax.ejb.CreateException

According to the book, it is not and I cannot figure out what is wrong?
Well, I am aware that most likely, that method needs to have some parameters, but in theory it can be very well without any. Also it does not need to be named �Create<something>, just Create should be OK as well. This in the home interface, of course.
The correct one as per the book is this one:

Public String ejbCreateAccount() throws javax.ejb.CreateException
 
M Mistroni
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
primary key must be Objects..

theres' another thread on the same issue in this forum

hth
marco
 
M Mistroni
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there. i found it.

check spec chap 10.6.13

the class must provide suitable implementaiton of hte hashCode and equals(OBject)

so, it cannot be a primitive.

I know, i missed that too.. got answer from checking spec/forum. I don't think this particularity is explained in HFEJB

hth
marco
 
Jaroslav Jarni
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer Marco!
I think I understand that, but that would apply only if the primary key must be class, and this of course in the case where primary key is comprised of more then one attribute, field, piece of data, name it whatever you like.
So we have two cases for the primary key issue.
In the simplest possible case, the primary key is only single field (let me put that in database terms to make it simple). And in that case we DO NOT need a class, spec is clear about this.
So in that case, I have not found anywhere in the spec where it says that primary key data type CANNOT be primitive, like �int�.
The spec does say that it is allowed for the primary key data type to be undefined or deferred until deploy time and in that case you are supposed to put Object as the data type.
So, is there any guru to explain this to me please?
 
Rajan Murugan
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when it is "int" how would you define in the dd the primary key ?
 
Jaroslav Jarni
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I agree there is <prim-key-class> in the DD, but even with that I was not sure. Since the container figures out the types for persistent fields based on abstract getters and setters in the bean class, I was not sure is this <prim-key-class> is mandatory if for example there is no need for the class, in the case where only one field is enough, so <primkey-field> might have been enough.
But then, it came to my mind that you must return null from ejbCreate() which is a sure sign that return data type must be an object and not a primitive.
Anyway, Rajan, thanks for the pointer.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic