Originally posted by Lionel Orellana:
hi all,
During the execution of a finder method an EJBObject is created but it's not associated with any bean instance. I understand the reason for this is that the container will still have to load the bean with data from the db when the client invokes a business method in case something changed between the call to the finder method and the call to the business method.
My question is, why the same logic doesn't apply for creates? From what I can gather on pages 328 and 329 of HFEJB, the bean leaves the pool and remains associated with its EJBObject after the call to create ends. Something could also change between creation and the client calling a business method, so isn't the container going to load the bean again before the next business method? Isn't it the same situation as finders?
Thanks!
The finder method is invoked on the home object, not on the EJBObject. Suppose you are in this scenario:
1) You've just created an entity and have got a reference to an entity's EJBObject stub
2) Supposed in this moment the database is not locked (let's say because the container finished the create transaction), someone changes the value in the record you've just added
3) Not aware of the changes, you invoke a business method on your EJBObject
The container will start a transaction (ensuring that the underlying persistent state cannot be corrupted - by, let's say, asking the db to lock a record), will load the bean with the latest record value and will executed the business method, updating the database with the bean's last state and ending the transaction. As you can see there is no risk for the container in letting you with a reference to a just created entity bean.