I posted this in the programming forum, but then got to thinking maybe it should be here... anybody got any ideas on this?
From examination, it appears (at least with my appserver WAS 5.1) that when creating an entity, the following happens:
- ejbCreate() is called, which results in an INSERT being performed on the database (my code) and a primary key returned.
- the primary key is assigned to the EntityContext object
- ejbPostCreate() is called
- the bean is (more or less) immediately passivated, so ejbStore() is called.
My question is related to the ejbCreate() method itself. It seems that this method is responsible for setting all bean fields (in essence by-passing the ejbLoad for the entity). This makes sense in most cases, as create usually already has all the information needed to synchronize the bean's state.
However, in some cases, a bean may need information that resulted from the actual INSERT statement. I am thinking, in particular of a field that is populated by a trigger on insert (or update). If this field is included in the entity, it still requires a SELECT to get the value that resulted from the INSERT.
My question is this: could I invoke ejbLoad() in ejbPostCreate() to completely synchronize the state of the bean after a create or is it considered bad practice?