This is what I found in the spec:
3.5 Entity Listeners and Callback Methods
" Lifecycle callbacks can invoke JNDI, JDBC, JMS, and enterprise beans.
" In general, portable applications should not invoke EntityManager or Query
operations, access other entity instances, or modify relationships in a
lifecycle callback method. [19]
[19] The semantics of such operations may be standardized in a future release of
this specification.
3.5.2 Semantics of the Life Cycle Callback Methods for Entities:
It is implementation-dependent as to whether callback methods are invoked before
or after the cascad-ing of the lifecycle events to related entities.
Applications should not depend on this ordering.
HTH,
-marina
Farrukh Najmi wrote:
>
> In my app when I persist an entity it cascades and persists sub-entities
> within the top level entity.
> I need to process each entry (top level and nested). I am wondering what
> constraints are placed
> in the kind of processing one can do in a Pre method of an
> EntityListener class. For example can I do:
>
> * Update of existing entities in the EntityManager and calling
> em.merge on them
> * Creation of new entities and calling em.persist on them
> * Removal of existing entities in the EntityManager using em.remove
> on them
>
> Also does the spec define the traversal order (is is depth-first or
> breadth-first). I can't tell though I would assume it should be
> depth-first.
>
> Thanks for any pointers.
>