-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Need advice on handling transistive persistence for remove
PostPosted: Mon Mar 03, 2008 12:40 pm 
Beginner
Beginner

Joined: Mon Dec 26, 2005 3:29 pm
Posts: 23
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?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
or 3 shallow attach the objects session.lock(object, LockMode.NONE);

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 12:17 pm 
Beginner
Beginner

Joined: Mon Dec 26, 2005 3:29 pm
Posts: 23
Emmanuel, thanks for your reply. The problem is that I don't want to expose to the callers anything but EntityManager itself. Your solution calls for the caller to issue the Session.lock() call before they modify and merge the object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.