struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stasica <>
Subject struts2+hibernate+spring - lazyInitaializationException
Date Sun, 18 Jul 2010 22:43:23 GMT

i've been testing very simply scenario using aforementioned technologies but
all i get is LazyInitializationException while trying to access my entity
collection. I've included some code snippets below to make myself very
clear. I don't think there is anything wrong with the attached code as most
of the examples i found on the Internet use exactly (at least i haven't seen
any differences ) this approach. This makes me believe that somehow s2 works
differently here and causes the problem (.. perhaps it's a long shot on my
part but perhaps attaching each action to the ThreadLocal is the problem ?
Surely it's not a problem of having or not having OpenSessionInViewFilter as
the call to hibernate doesn't originate from the view layer (jsp)


class Book{

  private List<Author> authors;


class BookDaoImpl {

 public Book find(int Id)

     Book sv = hibernateTemplate.get(Book.class, Id);  //this line works

     sv.getAuthors().size();  //this line throws LazyInitializationException

    return sv;

public void setSessionFactory(SessionFactory sessionFactory)
this.hibernateTemplate = new HibernateTemplate(sessionFactory);

*spring configuration xml*
<context:component-scan base-package="com.xx.service,com.xx.dao">
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"

<bean id="sessionFactory"
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<property name="hibernateProperties">
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>


*BeanManager - i'm using this class in struts actions to retrieve spring
beans as i don't want to use spring object factory shipped with struts2*

public class BeanManager {
        public static synchronized BeanManager getInstance() {
instance = new BeanManager();
return instance;

protected BeanManager()
URL url =
 ctx = new FileSystemXmlApplicationContext(url.getPath());


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message