-->
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.  [ 1 post ] 
Author Message
 Post subject: JBoss AS 6.x createNamedQuery call to detachQueryNonTxInvoca
PostPosted: Wed Sep 09, 2015 3:10 pm 
Newbie

Joined: Mon Jun 15, 2015 1:42 pm
Posts: 2
We are converting our application from JBoss AS 5.2 to JBoss AS 6.3. The createNamedQuery
method that is called by default in 6.3 is causing our code to throw a Hibernate exception, due to the detachQueryNonTxInvocation call within createNamedQuery method.

After calling em.createNamedQuery("someStringValue"), we call (back in our EJB) Hibernate.initialize(someEntity.getSomeCollection), which now results in the Hibernate Exception "collection is not associated with any session". The transaction atribute on that method is TransactionAttributeType.SUPPORTS

We use the Hibernate.initialize pattern in many places in our code base.

We can avoid the "collection is not associated with any session" exception in two ways:
1. Instead of passing in the default EntityManager to the Entity, pass in em.getEntityManagerFactory().createEntityManager()
or
2. After getting the result of the query, call HibernateThreadLocal.getSession().refresh(result) before calling Hibernate.initialize(someEntity.getSomeCollection).

Are either of the two "workarounds" above good practice, and why the change in JBoss 6.x to detach entities loaded by a query in a non-jta invocation?


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

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.