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 :
dispatcher-servlet.xml
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
}
exception (cutted ):
Code:
INFO: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:212)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:382)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:129)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:315)
at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.getConvertedValue(SelectCheckboxMenuRenderer.java:35)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.celleditor.CellEditor.processValidators(CellEditor.java:83)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.api.UIData.process(UIData.java:312)
at org.primefaces.component.api.UIData.processChildren(UIData.java:297)