• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question from SUN's ejb quiz

 
Tom Chen
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
8. At what point, precisely, in the life-cycle is a container-managed entity bean considered created?
A. Immediately prior to the execution of its ejbCreate() method
B. Immediately after the execution of its ejbCreate() method
C. After the CMP bean's data has been committed to the underlying persistent datastore
D. During the execution of its ejbPostCreate() method
Answer provided: B
However my answer is C. Let's assumpt that we have a transaction which create two entity beans:
1)transcation start
2)create EntityA -- call ejbCreate() of EntityA
3)create EntityB -- call ejbCreate() of EntityB
4)commit or rollback
after step 2) -- calling ejbCreate() of EntityA sucessfully, we may have error while calling ejbCreate() of EntityB, then the container would rollback the creation of EntityA. So from this point of view, the provided answer B is incorrect.
Welcome comments,
Tom
 
Jack Coleman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To restate the question:
At what point, precisely, in the life-cycle is a container-managed entity bean considered created?
I would agree with Sun's answer that the bean is "created" immediately after the execution of its ejbCreate() method. Bean creation and transaction isolation are two separate issues. Even if the container has not committed the bean to the datastore, it is still considered "created" because you have a new instance of a Primary Key object for that entity.
Synchonization of the EJB and the database is the container's responsibility. Given your assumptions I would answer yes to the interjected question.

1)transcation start
2)create EntityA -- call ejbCreate() of EntityA
2a) Do I have a "created" bean?
3)create EntityB -- call ejbCreate() of EntityB
3a) exception, ejbCreate never finished (no bean created)
4)commit or rollback
Comments?
[ January 07, 2003: Message edited by: Jack Coleman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic