aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ejbPostCreate()  for session/message beans 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 "ejbPostCreate()  for session/message beans" Watch "ejbPostCreate()  for session/message beans" New topic
Author

ejbPostCreate() for session/message beans

Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Just Curious about ejbPostCreate() method :
ejbPostCreate() method is applicable only to entity beans.
Can somebody tell me, what are the consequences if I try use it in my Session/Message Beans? I know, I shouldn't expect it to be called after the ejbCreate() method call but can I use it as a private method.
Will I get any deployment or run time errors?
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
hi, Vish.
I guess, you can add ejbPostCreate() method to SessionBean and MDB and compiler will not complain at all, but since this method is a callback method, it is intended for bean notification from EJB container, and EJB container does not suppose to call this method fo SB & MDB, this method will never be called (in a way it is called in Entity).
Also, remeber about ejbPostCreate() as method in which you can setup relations for Entity EJBs, in this method you can use newly created bean's ID for relationship creating. This is primary (IMHO) purpose of this method.
Cheers !!!


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Thanks Mikalai,
The method signatures of ejbPostCreate() method must correspond with the relevant ejbCreate() method, except for the return value which is primary key for ejbCreate() and void for ejbPostCreate() for entity beans.
How about the list of application exceptions declared in the method signatures? I read somewhere that they are not required to match...
Am I right?
Rashmi Tambe
Ranch Hand

Joined: Aug 07, 2001
Posts: 418
How about the list of application exceptions declared in the method signatures? I read somewhere that they are not required to match...

You r right vish...
however, while trying with some code, i came across a situation, which i a not able to u'stand.
i have a bean Employee. its local home has a create method as -
public Employee create(Integer id) throws CreateException, IOException;
the bean class has a ejbCreate method as -
public Integer ejbCreate(Integer EmpNo) throws IOException
when i do ejbc , i get follwoing exception -
[java] ERROR: Error from ejbc:
[java] In EJB Employee, method create(java.lang.Integer) on the local home interface throws java.rmi.RemoteException.
Methods on the local home interface must not throw java.rmi.RemoteException.

why? can't i throw any checked exception from create method? or does it have to be createException only?
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
Originally posted by Vish Kumar:
How about the list of application exceptions declared in the method signatures? I read somewhere that they are not required to match...
Am I right?


hi, Vish
At least I did not read in spec that list of throwable exceptions for ejbCreate and ejbPostCreate has to be the SAME,
so...
I could guess that they may have declare different exceptions in their signatures...
But how to hanle this situation... Client call "create()" method and as a result Container call ejbCreate + ejbPostCreate both methods on bean class. What happens if something bad happens in ejbCreate ? or ejbPostCreate ?
What spec says about this (page 195):

All the exceptions defined in the throws clause of the matching ejbCreate<METHOD> and ejbPostCreate<METHOD> methods of the enterprise Bean class must be included in the throws clause of the matching create method of the home interface (i.e., the set of exceptions defined for the create method must be a superset of the union of exceptions defined for the ejbCreate<METHOD> and ejbPostCreate<METHOD> methods).
The throws clause of a create<METHOD> method must include the javax.ejb.CreateException.

As we can see, ejbCreate and ejbPostCreate MAY have different list of application exceptions in throws definition, but all of them must present in "create()" declaration, because container would like to be prepared for something bad happened both in ejbCreate and ejbPostCreate.
Some note about "create()" method...
"create()" has to have : all exceptions declared in "ejbCreate()" +
all exceptions declared in "ejbPostCreate()" +
RemoteException (Remote view only) + CreateException (even if it is not declared for ejbCreate() or ejbPostCreate())
Think of "ejbCreate()" (or "ejbPostCreate()" ) as a BOSS (you see it has a CAPITAL letter in his name, so he IS a boss, and boss is free to declate CreateException or no; but "create()" - is a regular employee, it even has all it's name in lowercase, so he has no choice and it has to declare CreateException always).
Cheers
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Cheers Mikalai,
for the good explanation...

By the way, I like your Exception hierarchy in your online book. That makes it easy for me to remember...
Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
Rashmi,
If you have HFE book then on 625 page it says that one of EJB 2.0 restrictions is use of java.io package. IOException happens to be exactly in this package...
Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ejbPostCreate() for session/message beans