Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Losing non-managed (@Transient) when performing a merge/persist

586463Apr 18 2008 — edited Apr 18 2008
I thought I had a relatively simple problem to solve, but after many hours debugging and walking through code I can't find a solution. Please help...

Scenerio:
I am using the latest EclipseLink with Spring and JPA annotations. I have a need to perform additional JDBC operations during @PostPersist and @PostUpdate using data from the object I am persisting. Since I configured my EntityManager through spring I can easily get the current connection and perform straight JDBC within the current transaction.

The Good:
This works great for new objects. I get a call to my @PrePersist to setup the object and then a call to @PostPersist where I do the additional JDBC activity.

The Bad:
When I try to update the object things go very bad. Since I don't have a new object I need to perform a merge to not get the dreaded "cannot persist detached object" error. This is where the fun begins:

1. The first call I get is a @PostLoad. I determined that this is being called with the cached entity. Of course this cached entity does not contain any non-managed data from the object I am really trying to save. (This is a problem because I can't see my original data)

2. 2nd I get a call to @PreUpdate but not with my original data. I get called with the clone which does not include any of my original data. (Again this is a problem)

3. 3rd I get a call to @PostUpdate but again without my original data. I then happily (not) store the wrong data to the database and my application thinks everything went OK.

Editorial:
I understand the need for caching, however I can't understand how data from the original object can be thrown out during a persistence operation. Cached data needs to store both the up-to-date managed data ansd also any @Transient data. There can certainly be more "state" to an Entity than just the DBMS field value.

What I Tried:
1. I played with many cache settings with no good results.

2. I used to the SessionCustomizer to call a postMerge() on my object. Niether the source or the target contains my original data so no good merge happens.

Basically I need help making sure that my original data is used for an update instead of a clone???

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2008
Added on Apr 18 2008
3 comments
4,490 views