This week's book giveaway is in the Agile/Processes forum.
We're giving away four copies of Building Green Software: A Sustainable Approach to Software Development and Operations and have Anne Currie, Sarah Hsu , Sara Bergman on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

ejbPostCreate() for session/message beans

 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 3958
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Bartender
Posts: 3958
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic