Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about ejbPostCreate

 
Jason Hunt
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From book "master ejb 2nd", there is sth related to the usage of ejbPostCreate():

---------------------------
You might also use this method to reset certain
transaction-related parameters. For example, you
could keep a data status flag in the bean to indicate
whether a field has been changed. Because the bean
instance may have been used before, these fields
might have dirty data.
----------------------------

My question is why we need ejbPostCreate() to do the work rather than ejbCreate() ?

thanks in advance.

 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jason,

The quote above obviously applies to BMP entity beans and the exam doesn't cover them.
Now your question:

My question is why we need ejbPostCreate() to do the work rather than ejbCreate() ?


For CMP entity beans, ejbPostCreate() is typically used to update the relationships through a call to one or more CMR abstract setters.

Why do you need to wait till ejbPostCreate() for doing it? Because relationships are materialized in the db by PK/FK mappings and that in ejbCreate() the bean's PK is not available yet (the bean is said to have "no identity").

Regards,

Phil.
 
Jason Hunt
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Philippe, it is all cleared now.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic