Currently I working on implementing web based application with persistence to DB . I use Spring 3.2.3.RELEASE , Hibernate 3.5.6-Final , JSF 2.1.6 + PrimeFaces 3.5 .
I get org.hibernate.LazyInitializationException not a first time , before I solve it by adding FetchType.EAGER to problematic fields of bean , but this time it don't solve problem , I am suspecting that it is because collection that I try to fetch is enum . Also I try to implement org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter , but it also not solve the problem or I just fail to implement it correctly .
Here is code / configs :
web.xml :
dispatcher.servlet.xml :
problematic bean :
Exception happens when I try to save entity but before i get to SchedulingSettingsManagedBean.onSave .
Could you please give me a tip how to solve it ?
I get org.hibernate.LazyInitializationException not a first time , before I solve it by adding FetchType.EAGER to problematic fields of bean , but this time it don't solve problem , I am suspecting that it is because collection that I try to fetch is enum . Also I try to implement org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter , but it also not solve the problem or I just fail to implement it correctly .
Here is code / configs :
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">
<!-- Spring Context Configuration' s Path definition -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dispatcher-servlet.xml
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>mySessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext.
It is registered to Servlet Container -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Welcome Page -->
<welcome-file-list>
<welcome-file>pages/index.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF Servlet is defined to container -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping with servlet and url for the http requests. -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="......" />
<context:component-scan base-package="........." />
<tx:annotation-driven proxy-target-class="true" />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>database.properties</value>
</property>
</bean>
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="jdbcUrl" value="${db.url}" />
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="user" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="preferredTestQuery" value="select 1;" />
<property name="initialPoolSize" value="20" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="150" />
<property name="maxIdleTime" value="1800" />
<property name="idleConnectionTestPeriod" value="3600" />
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
...................
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="myDataSource" />
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
</beans>
Code:
@Entity
@Table(name = "SchedulingSettings")
public class SchedulingSettings implements Serializable
{
private static final long serialVersionUID = -8319141036288318816L;
@Id
@GeneratedValue
private int id;
@Column(name = "name", unique = true, nullable = false)
private String name;
@ManyToOne
@JoinColumn(name = "domainId", unique = false, nullable = false)
private Domain domain;
@Enumerated(EnumType.ORDINAL)
@Column(name = "language", unique = false, nullable = false)
private Language language;
@ManyToOne
@JoinColumn(name = "releaseId", unique = false, nullable = true)
private ReleaseEntity releaseEntity;
@Column(name = "maxTimeOfChanges", unique = false, nullable = true, columnDefinition = "timestamp")
private Date maxTimeOfChanges;
@ElementCollection(fetch = FetchType.EAGER)
@Enumerated(EnumType.ORDINAL)
@CollectionTable(name = "SchedulingSettings_BrowserType")
@Column(name = "browserTypes", unique = false, nullable = false, columnDefinition = "binary")
private Set<BrowserType> browserTypes;
@ManyToOne
@JoinColumn(name = "testCaseId", unique = false, nullable = true)
private TestCase testCase;
@ManyToOne
@JoinColumn(name = "testSuiteId", unique = false, nullable = true)
private TestSuite testSuite;
/// ..... getters / setters / helper methods
}
Could you please give me a tip how to solve it ?