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
theres' another thread on the same issue in this forum
Joined: Oct 03, 2005
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
Joined: Nov 09, 2006
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?
when it is "int" how would you define in the dd the primary key ?
With Regards,<br /> Rajan<br />"Java Rocks"
Joined: Nov 09, 2006
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.