-->
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.  [ 6 posts ] 
Author Message
 Post subject: NOT getting a LazyloadException
PostPosted: Thu Jun 26, 2008 6:49 am 
Newbie

Joined: Thu Jun 26, 2008 6:40 am
Posts: 4
I am usingg Hibernate EntityManager with Glassfish and I have configured the datasource with transaction type JTA . I have a relationship Customer->Order which I have specified a lazy. I am showing this in JSP (JSF ) pages. The architecture is JSF->Managed Bean -> Local (Stateless) Session Bean -> JPA (Hibernate EM)
My problem is that when I fetch the Customer (in a transaction), I can see the returned Set for order is 'CGLIB Enhanced'. If I now iterate over this collection in Managed Bean (the transaction has ended, I am not using opensessionview) , I see that hibernate issues a query (show_sql) instead of throwing the expected LazyInitialization exception.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 7:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Are you sure that the transaction ended? Do you use declarative transaction management or do you do this manually? Are you using a JTA system transaction?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 7:57 am 
Newbie

Joined: Thu Jun 26, 2008 6:40 am
Posts: 4
Yes. I am using @TransactionAttribute(TransactionAttributeType.REQUIRED)

<persistence-unit name="pPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/DS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>


Top
 Profile  
 
 Post subject: org.hibernate.LazyInitializationException auto_close_session
PostPosted: Fri Jun 27, 2008 6:42 am 
Newbie

Joined: Thu Jun 26, 2008 6:40 am
Posts: 4
If I use the property
<property name="hibernate.transaction.auto_close_session"
value="true"/>
then I do get a org.hibernate.LazyInitializationException

Howerver If I set it to false , the session is still active after the Tx end (I see it in glassfish logs that TX has ended) . Any lazy associations are fetched with the followin log entry
TransactionFactory reported no active transaction; Synchronization not registered

I am still confused about the correct settings as the documentation says it should be auto!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 7:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

sounds strange. I assume you are also injecting the entity manager (@PersistenceContext). In this case the persistence context should be bound to your JTA transaction and the container should open/close the persistence context at the beginning/end of your business method. I don't think that hibernate.transaction.auto_close_session should have been necessary.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 9:24 am 
Newbie

Joined: Thu Jun 26, 2008 6:40 am
Posts: 4
The context is not destroyed!! This could be glassfish issue due to use of @Local in the stateless session bean because calling the sessin bean twice in succession gives me the same persistence context and this may explain why the session is stll active after Tx has completed. It is destroyed only when the managedbean (JSF) call returns.


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