Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Hibernate+icefaces

  Asked By: Grant    Date: Sep 18    Category: Java    Views: 1492
  

I am using Hibernate and Icefaces in my web project. but when i am going to load an entity from database this error occurs.
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
It seems when it is doing lazyloading, the session is closed. What is the solution for this problem?

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Josie Roberts     Answered On: Sep 18

Use DTO pattern instead of using entities directly if you insists to standardize your framework (EJB, JPA, JSF , and other JSR-ed techs) , otherwise you must inject something like hibernate  remote lazy loading into your framework which makes you dependent on Hibernate,

https://www.hibernate.org/377.html

 
Answer #2    Answered By: Marc Anderson     Answered On: Sep 18

Which version of hibernare are you using ? and do you actually intend to lazy load  objects and configured hibernate  to do so?

 
Answer #3    Answered By: Kiet Jainukul     Answered On: Sep 18

I am using Hibernate 3.2.5 and i am intended to use the lazy loading feature. i think the default Fetch type is "LAZY" and it not nedde to state it .

 
Answer #4    Answered By: Mae Roberts     Answered On: Sep 18

Yes. The default fetch type by default is lazy in hibernate  3. How do you load  the object ? is your application using a framework like Spring to handle hibernate calls and transactions or are you doing that manually yourself in some kind of DAO ?

 
Answer #5    Answered By: Freda Lane     Answered On: Sep 18

I am using only Hibernate + Icefaces and no other framework like Spring or Seam. my problem  solved. i changed my code form session.load(..., ...) to session.get(... , ...). but annother thing is that Hibernate does not load  associatios lazily. I got this using debugging.

 
Answer #6    Answered By: Hooriya Khan     Answered On: Sep 18

You can use this code,it might help you.

public <T> Object refresh(T obj){
Session session= HibernateUtil.getSession();
Transaction tx=session.beginTransaction();
session.refresh(obj);
tx.commit();
tx=null;
return obj;
}

 
Answer #7    Answered By: Adalia Fischer     Answered On: Sep 18

alternatively you can use a filter to open the session  in your service objects.
if you are using spring with hibernate, you can config OpenSessionInViewFilter in web.xml.
if not you can find something simillar for your framework or implement it yourself.

 
Answer #8    Answered By: Tracy Myers     Answered On: Sep 18

The problem  is so simple, I told you in my first email, you have bound your
Ice faces UI components directly to your JPA entities, I guess you have used a stateless http servlets or ejb session  bean, that's the reason you loose and detach the entities from persistence layer (entity manager).

There are three popular solutions for that:
1. The most popular is using DTO pattern, so you get rid of everything related to the persistence layer, but you duplicate your value object classes.
2. Using Hibernate remote lazy loading
3. Using JBoss SEAM patterns for developing RAD web  applications

 
Didn't find what you were looking for? Find more on Hibernate+icefaces Or get search suggestion and latest updates.