Hi. I know this is a common problem. I've read the forum posts regarding this, searched the web, tried multiple approaches but haven't hit the solution. My thoughts are I might be missing an annotation for @Transactional, OSIV is set up incorrectly, or something with Struts2 and OSIV is off. Would appreciate any feedback, have spent hours on this moving code around. Learned a lot but can't get the solution.
Eclipse console is showing the OSIV Debug messages (e.g. "DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp")
The error is "failed to lazily initialize a collection of role: com.lindoro.model.fbuilder.Strategy.formulae, no session or session was closed".
The data is grabbed correctly with "(fetch=FetchType.EAGER)"
Help would be very appreciated.
----------------------------------
Strategy.java
Code:@Entity @Table(name="strategies") public class Strategy { @Id @GeneratedValue @Column(name="id") private int id; @ManyToMany @JoinTable(name = "strategies_to_formulae", joinColumns = { @JoinColumn(name="strategy_id", unique = true) }, inverseJoinColumns = { @JoinColumn(name="formula_id") } ) private List<Formula> formulae; <snip>
Formula.java
StrategyDaoJdbc.javaCode:@Entity @Table(name="formulae") public class Formula { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="id") private int id; @Column(name="ui_name") private String uiName; <snip>
ApplicationContext.xmlCode:@Transactional public class StrategyDaoJdbc implements StrategyDao { private SessionFactory sessionFactory; public StrategyDaoJdbc(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public List<Strategy> getStrategyList() { return sessionFactory.getCurrentSession().createQuery("from Strategy").list(); } <snip>
Code:<bean id="strategyDao" class="com.lindoro.repository.fbuilder.StrategyDaoJdbc"> <constructor-arg ref="sessionFactory"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>com.lindoro.model.fbuilder.Strategy</value> <value>com.lindoro.model.fbuilder.Formula</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <tx:annotation-driven transaction-manager="txManager"/> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean>
web.xml
Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>lindoro</display-name> <!-- FILTERS --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- FILTER MAPPINGS --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- WELCOME FILES --> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- TAGLIBS --> <jsp-config> <taglib> <taglib-uri>/WEB-INF/lib/struts-tags.tld</taglib-uri> <taglib-location>/WEB-INF/taglib/struts-tags.tld</taglib-location> </taglib> </jsp-config> <!-- Hibernate OpenSession Filter --> <filter> <filter-name>hibernateFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>


Reply With Quote