This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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 ]
 
today's feeble attempt to support the empire
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic