-->
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.  [ 2 posts ] 
Author Message
 Post subject: JSF/Hibernate: How do i manage hibernate sessions in JSF?
PostPosted: Mon Aug 16, 2010 7:21 am 
Newbie

Joined: Sun Aug 15, 2010 10:35 am
Posts: 4
Using JSF/Richfaces and Hibernate. In my hybernate mapping file, i have put
Quote:
<property name="current_session_context_class">thread</property>

I use getCurrentSession to get the session.
Code:
Session session = SessionFactoryUtil.getInstance().getCurrentSession(); 

I have a class Order which contains a collection of OrderItem objects. I display a list of Orders in a xhtml page. The aim is that when i select a particular order, it will be displayed in a different xhtml page together with its children (OrderItems). However i get the "LazyInitializationException: Session has been closed" problem.

I am in a dilemma because for my implementation, i am forced to open transactions for everything, e.g. to get the list of Orders, i have to open and commit a transaction. Unfortunately, committing a transaction seems to close the session. How do i make the session to persist through the application session, while at the same time allowing commits to a Database?


Top
 Profile  
 
 Post subject: Re: JSF/Hibernate: How do i manage hibernate sessions in JSF?
PostPosted: Tue Aug 17, 2010 5:15 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
to solve this kind of issues the Seam framework was created, standardized now as CDI (Seam 3 core is named Weld, the reference implementation of CDI).
please see http://www.seamframework.org.

Alternatively if you're using JPA in JavaEE6 look for the extended persistence context, that's the same pattern used in Seam: you get a persistence context (similar to Session) associated to your session beans, so you can span your logic in multiple page views.

You should *not* bind the session to the current thread, as you don't know if the next page request is going to be served by the same thread, so you need another placeholder for the session. That's why it's handy to look for the before mentioned frameworks. Seam comes with great examples using Hibernate, RichFaces and xhtml using facelets, so it looks like suited to your case.

_________________
Sanne
http://in.relation.to/


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