Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Add related objectes during persist

Hello,
we are currently using the preUpdate and postInsert events to add other objects to the currently inserted entity (via session.insertObject(obj) ).

As far as I read in the JPA 2.0 specification, these events should only be used to modify the object's attributes but not for adding other entities.
https://download.oracle.com/otn-pub/jcp/persistence-2.0-fr-oth-JSpec/persistence-2_0-final-spec.pdf   (page 93)
"In general, the lifecycle method of a portable application should not invoke EntityManager or Query operations, access other entity instances, or modify relationships within the same persistence context"

After persisting the entity, it is not in sync with the database, therefore. That's why we want to get rid of this part of code. 
Unfortunately, I don't know any good replacement, how to do it.

Short description of our use case:
We have "support-ticket" entities and there are different rules, which employees should be added as observers (priority, customer etc.).
Currently, these rules are checked within the postInsert event and the m:n relation table is filled during this event.
The ticket entities can be stored at different locations in the source code. Some tickets are attached to other objects and persisted as child objects.
Thus, I didn't find a good way to handle this and comply with the specs.

Is there any other event or place, where I can add new child objects / references to an entity during persisting?
I hope the use case is understandable.
Any suggestions are welcome.

Thanks in advance!
Tom


Back to the top