-->
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.  [ 4 posts ] 
Author Message
 Post subject: error with lazy initialization
PostPosted: Wed Sep 17, 2008 9:58 am 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
hi, I have a very simple code snippet.

public List<Order> findAll() {
try {
List<Order> retList = getHibernateTemplate().find("From Order");

if (retList != null && !retList.isEmpty()) {
for (Order order: retList) {
getHibernateTemplate().initialize(order.getLines());
}
}

return retList;
} catch (RuntimeException re) {
throw re;
}
}

It keeps failing at

getHibernateTemplate().initialize(order.getLines());

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)

I set lazy="true" (by default) at Lines Set in Order. I am using Spring servlet to wire the DAO into my service object. If I remove initialize() line, it's ok as long as I don't access Lines set. Any thought?

Thanks.


Top
 Profile  
 
 Post subject: bump up for answer ...
PostPosted: Thu Sep 18, 2008 8:29 am 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
bump up for answer ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 10:56 am 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
Does getHibernateTemplate() always create a new session.

If I put

Session sess = getSession(false) at the begining. I got

No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here.

I thought it should share one session at least in one thread (in this case, one method).

Any thoughts?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 1:23 pm 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
false alarm, I got it sorted out.


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