-->
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.  [ 2 posts ] 
Author Message
 Post subject: No Hibernate Session bound to thread
PostPosted: Sun Jun 12, 2005 11:42 am 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.4

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="com.stufftolet.model.Posting.Category"
table="CATEGORY"
lazy="true"
>

<id
name="id"
column="CATEGORY_ID"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Category.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<version
name="version"
column="version"
type="java.lang.Integer"
/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="NAME"
length="50"
unique-key="UNIQUE_NAME_AT_LEVEL"
not-null="true"
/>
</property>

<many-to-one
name="parentCategory"
class="com.stufftolet.model.Posting.Category"
cascade="none"
outer-join="false"
update="true"
insert="true"
foreign-key="FK1_PARENT_CATEGORY_ID"
>
<column
name="PARENT_CATEGORY_ID"
unique-key="UNIQUE_NAME_AT_LEVEL"
not-null="false"
/>
</many-to-one>

<set
name="childCategories"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
batch-size="10"
>

<key
>
<column
name="PARENT_CATEGORY_ID"
/>
</key>

<one-to-many
class="com.stufftolet.model.Posting.Category"
/>

</set>

<set
name="categorizedItems"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
outer-join="false"
>

<key
>
<column
name="CATEGORY_ID"
length="16"
not-null="true"
/>
</key>

<one-to-many
class="com.stufftolet.model.Posting.CategorizedItem"
/>

</set>

<property
name="created"
type="java.util.Date"
update="false"
insert="true"
column="CREATED"
not-null="true"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Category.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
public Collection findAllCategory(boolean onlyRootCategories){

Collection categories;

if (onlyRootCategories) {
Criteria crit = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Category.class);
categories = crit.add(Expression.isNull("parentCategory")).list();
} else
categories = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Category.class).list();

return categories;
}


Full stack trace of any exception that occurs:

[junit] Testcase: testFindCategory(com.stufftolet.dao.CatalogDAOTest):
Caused an ERROR
[junit] No Hibernate Session bound to thread, and configuration does not all
ow creation of non-transactional one here
[junit] org.hibernate.HibernateException: No Hibernate Session bound to thre
ad, and configuration does not allow creation of non-transactional one here
[junit] at org.springframework.orm.hibernate3.LocalSessionFactoryBean$Tr
ansactionAwareInvocationHandler.invoke(LocalSessionFactoryBean.java:960)
[junit] at $Proxy0.getCurrentSession(Unknown Source)
[junit] at com.stufftolet.dao.hibernate.CatalogDAOHibernate.findAllCateg
ory(CatalogDAOHibernate.java:66)
[junit] at com.stufftolet.dao.CatalogDAOTest.testFindCategory(CatalogDAO
Test.java:51)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)

Name and version of the database you are using:MySql 4.1.12

Hi guys,

When I was testing a composite pattern retrieve function, which is

categories = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Category.class).list();

i got the above exception. Anyone pls kindly assist, Thank you !

regards,
prettyhandling


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 12, 2005 12:09 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you want to use Spring, go to their forum.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.