Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Background: I'm using session-per-request pattern without Transactions.
How is it possible that I can pass the isConnected test, but then fail in the Hibernate.initialize method with a HibernateException stating disconnected session?
Hibernate version:
2.1.8
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.skillsoft.ilt.beans">
<class name="Course" table="iltCourse" lazy="false">
<id name="ID" column="ID" unsaved-value="0">
<generator class="native"/>
</id>
<property name="lastModified" column="lastModified" type="timestamp"/>
<property name="name" column="name"/>
<property name="number" column="number"/>
<property name="description" column="description"/>
<property name="duration" column="duration"/>
<property name="closingDays" column="closingDays"/>
<property name="cost" column="cost"/>
<property name="currency" column="currency"/>
<property name="mastery" column="mastery"/>
<property name="instructorPrivileged" column="instructorPrivileged"/>
<property name="approvalRequired" column="approvalRequired"/>
<property name="active" column="active"/>
<property name="language" column="language"/>
<property name="sessionApprovalRequired" column="sessionApprovalRequired"/>
<many-to-one name="sessionApprover" class="User" column="sessionApprover"/>
<many-to-one name="ownedBy" class="User" column="courseOwner"/>
<many-to-one name="facility" column="facility" class="Facility"/>
<many-to-one name="classroom" column="classroom" class="Classroom"/>
<many-to-one name="owner" column="owner" class="Contact"/>
<!-- bag => Collection, unordered, allows duplicates -->
<bag
name="sessions"
table="iltSession"
inverse="true"
lazy="true"
order-by="number"
cascade="all-delete-orphan"
fetch="select"
batch-size="1">
<key column="course"/>
<one-to-many class="Session"/>
</bag>
<!-- bag => Collection, unordered, allows duplicates -->
<bag
name="interestList"
table="iltCourseInterest"
inverse="true"
cascade="all-delete-orphan"
lazy="false"
order-by="uzer"
fetch="select"
batch-size="1">
<key column="course"/>
<one-to-many class="CourseInterest"/>
</bag>
<!-- bag => Collection, unordered, allows duplicates -->
<bag
name="attrValues"
table="iltExtAttrCourse"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
fetch="select"
batch-size="100">
<key column="courseid"/>
<many-to-many class="ExtAttrCourse" column="valueid"/>
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
...
if (((HibernateBaseDao)dao).isConnected() && !Hibernate.isInitialized(course.getSessions())) {
try {
Hibernate.initialize(course.getSessions());
} catch (Exception e) {
throw new DaoException("could not initialize course sessions", e);
}
}
...
Full stack trace of any exception that occurs:
Caused by: org.hibernate.HibernateException: disconnected session
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:278)
at org.hibernate.Hibernate.initialize(Hibernate.java:293)
at com.skillsoft.ilt.actions.CourseAction.requestHelper(CourseAction.java:606)
Name and version of the database you are using:
SQL Server 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: