-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Have session connection, but get exception disconnected sess
PostPosted: Mon May 01, 2006 4:24 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 10:29 am
Posts: 21
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:


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 4:51 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
please use correct [ c o d e] editor tags available to make your code sections readable. Thanks !!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 4:56 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 10:29 am
Posts: 21
Code:
<?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:
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);
                }
            }


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 5:13 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
This is the code in AbstractPersistentCollection.forceInitialization() in version 3.x

Code:
if (session==null) {
   throw new HibernateException("collection is not associated with any 
                                                session");
}
if ( !session.isConnected() ) {
   throw new HibernateException("disconnected session");
}


Somewhere your code is disconnecting the session.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 5:20 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 10:29 am
Posts: 21
How is this code getting "session"? Perhaps it is referencing a session which is actually disconnected versus the one referenced by my "wrapper" HibernateBaseDao.isConnected. HibernateBaseDao.isConnected implementation:
Code:
    public boolean isConnected() {
        return session.isConnected();
    }


BTW, my original post stated version 2.1.8, but this is a problem in 3.0.5 as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.