-->
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.  [ 5 posts ] 
Author Message
 Post subject: merge generates extra select using EntityManager
PostPosted: Fri May 19, 2006 6:54 am 
Newbie

Joined: Thu Apr 28, 2005 12:46 am
Posts: 6
Is there a way to avoid the extra select generated by em.merge() while reattaching and updating changes to an entity. T

There was a way by which this was possible in Hibernate Session. By locking an object to the session, make changes and then invoke saveOrUpdate().

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 9:36 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
What about em.lock? ;-)

Code:
javax.persistence
Interface EntityManager

public interface EntityManager

Interface used to interact with the persistence context.

Method Summary
void    clear()
          Clear the persistence context, causing all managed entities to become detached.
void    close()
          Close an application-managed EntityManager.
boolean    contains(Object entity)
          Check if the instance belongs to the current persistence context.
Query    createNamedQuery(String name)
          Create an instance of Query for executing a named query (in EJB QL or native SQL).
Query    createNativeQuery(String sqlString)
          Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
Query    createNativeQuery(String sqlString, Class resultClass)
          Create an instance of Query for executing a native SQL query.
Query    createNativeQuery(String sqlString, String resultSetMapping)
          Create an instance of Query for executing a native SQL query.
Query    createQuery(String ejbqlString)
          Create an instance of Query for executing an EJB QL statement.
<T> T
   find(Class<T> entityClass, Object primaryKey)
          Find by primary key.
void    flush()
          Synchronize the persistence context to the underlying database.
FlushModeType    getFlushMode()
          Get the flush mode that applies to all objects contained in the persistence context.
<T> T
   getReference(Class<T> entityClass, Object primaryKey)
          EntityManager Enterprise JavaBeans 3.0, Proposed Final Draft Entity Operations 39 12/19/05 Sun Microsystems, Inc.
EntityTransaction    getTransaction()
          Return the resource-level transaction object.
boolean    isOpen()
          Determine whether the EntityManager is open.
void    lock(Object entity, LockModeType lockMode)
          Set the lock mode for an entity object contained in the persistence context.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 11:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
em.lock() is actually not equivalent to session.lock since the lock modes are differents (same names but different semantics).
You'll have to rely on the underlying session object

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 1:05 am 
Newbie

Joined: Thu Apr 28, 2005 12:46 am
Posts: 6
emmanuel wrote:
em.lock() is actually not equivalent to session.lock since the lock modes are differents (same names but different semantics).
You'll have to rely on the underlying session object


Thanks for the response.

Will there be a future release of the hibernate EntityManager addressing this requirement? Since falling back on the Hibernate Session to do this reduces code portability.

Please acknowledge.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 1:20 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
jv_400 wrote:
Will there be a future release of the hibernate EntityManager addressing this requirement?


This is how ejb3 is specified - so it's not to the Hibernate EM to address this - which is already addressed in pure Hibernate.

jv_400 wrote:
Since falling back on the Hibernate Session to do this reduces code portability.


Write your own wrapper entry point - which you will easily implement for different ORM frameworks. You have tons of ways to do it - interceptors, injection, jndi lookup, ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.