Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Leonardo Carreira wrote:Hi Valmir Cinquini..
![]()
You could try to use HQL for getting the an Object or list of Objects that you want..
Hope that help..
Please correct me if i'm wrong..
Thanks..![]()
Mark Spritzler wrote:
When you are outside of your session and you try to access that collection in any way, including size(), the Proxy will try to load the data, but since there is no Session around anymore, which means no Connection to the database, then it will through a LazyInitializationException. Because you don't have the data and now you are trying to get it without a means to get it.
Valmir Cinquini wrote:
That's my problem. Hibernate is trying to load the collection even when I dont want to. I'm not calling size() or trying to read any item from the collection. But Hibernate loads the collection data. As the session is closed, so I got the exception. How to avoid that?
public List<Lote> list() throws MDIException {
Session session = HibernateUtil.getSessionFactory().openSession();
List<Lote> lista = null;
Transaction tr = null;
try {
tr = session.beginTransaction();
lista = (List<Lote>) session.createQuery("from Lotes").list();
tr.commit();
} catch (HibernateException ex) {
tr.rollback();
throw new MDIException("Can't get list of Lotes", ex);
} finally {
session.close();
}
return lista;
}
David Newton wrote:Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the
button.
Mark Spritzler wrote:The code or jsp/jstl tags is after a call to that method, not that method. If you can step through the code and find it loading the collection before the commit/close call then let us know, but it won't fetch it in that call, unless you have it set as eager fetch with I think you said it didn't
Mark
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|