• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

relationships and ejbPostCreate()

 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the place where I work, we use EJB, although I'm studying these properly now for the certification. We currently have related tables (let's say a Movie-Director) relationship. Because I didn't know about ejbPostCreate I never set the CMR field in this method. However I can ensure that, having declared the relationship between Movies and Director, if the client uses a CMR abstract method on the Director entity bean class, a collection of movies is returned (I can ensure it because, as I said, we're using in at work). So my question is: why shall I invoke the CMR setter method in the ejbPostCreate? Is this necessary? If so, how does it come that I can get all the related fields for an entity bean, even if I don't invoke the CMR setter in the ejbPostCreate()?

Thanks for any answer.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
However I can ensure that, having declared the relationship between Movies and Director, if the client uses a CMR abstract method on the Director entity bean class, a collection of movies is returned (I can ensure it because, as I said, we're using in at work).
If you are calling an abstract method on the entity bean, it means that the entity bean already exists and thus that the relationships have been set already at the time the bean was created. Actually, ejbCreate/ejbPostCreate are called only when the entity bean is created the first time in the DB. When the bean is already in a table somewhere, you usually get them using finder or select methods which will retrieve existing entity beans from the DB. Then the container will call ejbActivate on it to send it to the READY state and then ejbLoad to populate the fields.

If you create yourself new beans you are not required to set the relationship fields in the ejbPostCreate method. You can also invoke create() on the home which will trigger ejbCreate/ejbPostCreate on the bean class and then use the setter methods for setting relationship fields as normal. The requirement is not to set relationship fields in the ejbCreate method because the identity of the bean is not yet known. But after create() has been invoked you may set the relationships at any time but before the relationship field is actually used.

I hope this makes sense to you.
[ July 19, 2004: Message edited by: Valentin Crettaz ]
 
There's a city wid manhunt for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic