hi, 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)
*Entity* @Entity class Book{ @OneToMany..... private List<Author> authors; } *DAOImpl* class BookDaoImpl { public Book find(int Id) { Book sv = hibernateTemplate.get(Book.class, Id); //this line works fine sv.getAuthors().size(); //this line throws LazyInitializationException return sv; } @Autowired @Qualifier("sessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { this.hibernateTemplate = new HibernateTemplate(sessionFactory); } } *spring configuration xml* * * <beans...> <context:component-scan base-package="com.xx.service,com.xx.dao"> </context:component-scan> <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> ..</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list>..... <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> </beans> *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() { if(instance==null) { instance = new BeanManager(); } return instance; } protected BeanManager() { URL url = BeanManager.class.getClassLoader().getResource("applicationContext.xml"); ctx = new FileSystemXmlApplicationContext(url.getPath()); } }