aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ejbCreate method for Entity bean 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 "ejbCreate method for Entity bean" Watch "ejbCreate method for Entity bean" New topic
Author

ejbCreate method for Entity bean

Jaroslav Jarni
Greenhorn

Joined: Nov 09, 2006
Posts: 3
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

Joined: Oct 03, 2005
Posts: 62
Hi,
primary key must be Objects..

theres' another thread on the same issue in this forum

hth
marco
M Mistroni
Ranch Hand

Joined: Oct 03, 2005
Posts: 62
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

Joined: Nov 09, 2006
Posts: 3
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

Joined: Jun 24, 2006
Posts: 182
when it is "int" how would you define in the dd the primary key ?


With Regards,<br /> Rajan<br />"Java Rocks"
Jaroslav Jarni
Greenhorn

Joined: Nov 09, 2006
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ejbCreate method for Entity bean
 
Similar Threads
Entity bean question - HFEJB pag 363, exe: 5!
choosing between home business methods and finders
CreateException & FinderException?
Coffe Cream on EB - Mistakes/Doubt #2
ejbCreate query