Hibernate version: 3.1
As per the JPA specs, an attempt to merge data between two entity managers results in the creation of a new managed entity (i.e. a load from the database). Now, this causes a problem when using native queries if those queries return computed columns (because Hibernate does not know about those columns).
At the time, we decided to create an EntityManager proxy that delegates a call to merge to Hibernate's Session SaveOrUpdate method. This works fine, however it causes a problem when transistive persistence attempts to remove a detached entity. As per the JPA spec, removing a detached entity throws an IllegalStateException. Now, generally this is solved during a call to merge which reloads the entity, making it managed (and not detached). But our proxy sidesteps this and the detached object remains detached.
How should we deal with this? As far as I can tell, we have two options:
1. Physically load the object graph into the current EntityManager. Expensive, but not worse than what the spec calls for (for better or worse).
2. Subclass the org.hibernate.ejb.event.EJB3DeleteEventListener class and override the performDetachedEntityDeletionCheck method.
Which, if any, would be advisable?