-->
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: problem with hibernate session
PostPosted: Tue Oct 12, 2010 2:38 pm 
Newbie

Joined: Tue Oct 12, 2010 2:19 pm
Posts: 4
Hi I have a problem with the session hibernate
Quote:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:299)
at $Proxy0.getCurrentSession(Unknown Source)
at retrieveByCriteria(AbstractHibernateDao.java:111)
at retrieveByCriteria(AbstractHibernateDao.java:95)
at retrieveEntriesByCriteria(HibernateEntryDao.java:81)
at testRetrieveEntriesByCriteria(HibernateEntryDaoTest.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



And my code
Code:
package database;

import java.io.File;
import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.util.List;

import junit.framework.TestCase;

import org.dbunit.IDatabaseTester;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.PropertiesBasedJdbcDatabaseTester;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import Entry;
import EntrySearchCriteria;

public class HibernateEntryDaoTest extends TestCase {
   private IDatabaseTester databaseTester;
   IEntryDao entryDao;

   public HibernateEntryDaoTest(String name) throws Exception {
      super(name);
   }

   protected void setUp() throws Exception {
      ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
      "spring-fbi-configTest.xml");
entryDao = (IEntryDao) ctx.getBean("dao.entry");

      System.setProperty(
            PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS,
            "org.hsqldb.jdbcDriver");

      System.setProperty(
            PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL,
            "jdbc:hsqldb:fbiBpsa");
      System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME,
            "SA");
      System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD,
            "");
      databaseTester = new PropertiesBasedJdbcDatabaseTester();
      
      IDatabaseConnection connectionHsql = databaseTester.getConnection();

      databaseTester.setDataSet(getDataSet());
      // will call default setUpOperation
      databaseTester.onSetup();

   }

   protected IDataSet getDataSet() throws Exception {
      return new FlatXmlDataSetBuilder().build(new FileInputStream(
            ("src\\test\\resources\\full.xml")));
   }

   public void testRetrieveEntriesByCriteria() throws MalformedURLException,
         DataSetException {
      EntrySearchCriteria searchCriteria = new EntrySearchCriteria();

      List<Entry> entriesListResult = entryDao
            .retrieveEntriesByCriteria(searchCriteria);
      assertEquals(entriesListResult.size(),29);
      IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new File(
            "expectedDataSet.xml"));

   }

   protected void tearDown() throws Exception {
      // will call default tearDownOperation
      databaseTester.onTearDown();
   }

}


and my spring file
Code:
<?xml version="1.0" encoding="UTF-8"?>

<beans
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
      http://www.springframework.org/schema/jee   http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
      http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
      http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-2.0.xsd
   "
>
   <!--//////////////////////////////////////////////////////////////////////////-->
   <!--////////////////////////////// Placeholders //////////////////////////////-->
   <!--//////////////////////////////////////////////////////////////////////////-->
   
   <bean
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      id="propertyConfigurer"
   >
      <property name="location" value="spring-fbiTest.properties"/>
   </bean>

   <!--//////////////////////////////////////////////////////////////////////////-->
   <!--////////////////////////// Data Access Objects ///////////////////////////-->
   <!--//////////////////////////////////////////////////////////////////////////-->



   <bean
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"
      id="ds.fbi"
   >
      <property name="driverClassName" value="${ds.fbi.driver}"/>
      <property name="password" value="${ds.fbi.password}"/>
      <property name="url" value="${ds.fbi.url}"/>
      <property name="username" value="${ds.fbi.username}"/>
   </bean>
   
   <bean
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
      destroy-method="destroy"
      id="sf.fbi"
   >
      <property name="dataSource" ref="${sf.fbi.datasource}"/>
      <property name="hibernateProperties">
         <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="properties">
               <props>
                  <prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop>
                  <prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop>
                  <prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop>
                  
                  <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
                  <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                  <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                  
                  <prop key="hibernate.current_session_context_class">thread</prop>
                  <prop key="hibernate.dialect">${sf.fbi.dialect}</prop>
                  <prop key="hibernate.hbm2ddl.auto">${fbi.autocreate}</prop>
                  <prop key="hibernate.jdbc.batch_size">20</prop>
                  <prop key="hibernate.show_sql">false</prop>
               </props>
            </property>
         </bean>
      </property>
      
      <property name="mappingResources">
         <list>
            <value>hibernate/Entry.hbm.xml</value>
         </list>
      </property>
   </bean>

   [B]<bean
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"
      id="tm.fbi"
   >
      <property name="sessionFactory" ref="sf.fbi"/>
   </bean>[/B]

   <tx:advice
      id="ta.fbi"
      transaction-manager="tm.fbi"
   >
      <tx:attributes>
         <tx:method name="create"/>
         <tx:method name="createOrUpdate"/>
         <tx:method name="delete"/>
         [B]<tx:method name="retrieve*"/>
         <tx:method name="retrieveEntriesByCriteria"/>[/B]
         <tx:method name="test*"/>
         <tx:method name="update"/>
         <tx:method name="clearPrices"/>
      </tx:attributes>
   </tx:advice>

   <bean
      abstract="true"
      class="AbstractHibernateDao"
      id="abstractHibernateDao.fbi"
   >
      <property name="sessionFactory" ref="sf.fbi"/>
   </bean>
   
   
   
   <bean
      class="HibernateEntryDao"
       id="dao.entry"
      parent="abstractHibernateDao.fbi"
   />
</beans>

Like you can see, I have a transaction to my dao
See in bold
I don t know what to do


Top
 Profile  
 
 Post subject: Re: problem with hibernate session
PostPosted: Tue Oct 12, 2010 5:30 pm 
Newbie

Joined: Tue Oct 12, 2010 2:19 pm
Posts: 4
Ok, I changed my strategy.
Now, I use TransactionProxyFactoryBean
but the result is the same
Code:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
      http://www.springframework.org/schema/jee   http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
      http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
      http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-2.0.xsd
   ">
   <!--
      //////////////////////////////////////////////////////////////////////////
   -->
   <!--
      ////////////////////////////// Placeholders
      //////////////////////////////
   -->
   <!--
      //////////////////////////////////////////////////////////////////////////
   -->

   <bean
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      id="propertyConfigurer">
      <property name="location" value="spring-fbiTest.properties" />
   </bean>

   <!--
      //////////////////////////////////////////////////////////////////////////
   -->
   <!--
      ////////////////////////// Data Access Objects
      ///////////////////////////
   -->
   <!--
      //////////////////////////////////////////////////////////////////////////
   -->



   <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
      id="ds.fbi">
      <property name="driverClassName" value="${ds.fbi.driver}" />
      <property name="password" value="${ds.fbi.password}" />
      <property name="url" value="${ds.fbi.url}" />
      <property name="username" value="${ds.fbi.username}" />
   </bean>

   <bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
      destroy-method="destroy" id="sf.fbi">

      <property name="dataSource" ref="${sf.fbi.datasource}" />
      <property name="hibernateProperties">
         <bean
            class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="properties">
               <props>
                  <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
                  <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                  <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                  <prop key="hibernate.dialect">${sf.fbi.dialect}</prop>
                  <prop key="hibernate.hbm2ddl.auto">${fbi.autocreate}</prop>
                  <prop key="hibernate.jdbc.batch_size">20</prop>
                  <prop key="hibernate.show_sql">false</prop>
                  <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory
                  </prop>
               </props>
            </property>
         </bean>
      </property>

      <property name="mappingResources">
         <list>
            <value>hibernate/ChangeLog.hbm.xml</value>
            <value>hibernate/Fees.hbm.xml</value>
            <value>hibernate/Entry.hbm.xml</value>
            <value>hibernate/Correspondents.hbm.xml</value>
            <value>hibernate/ResidenceTaxes.hbm.xml</value>
            <value>hibernate/CorrespondentFees.hbm.xml</value>
            <value>hibernate/FeeTypes.hbm.xml</value>
            <value>hibernate/Departments.hbm.xml</value>
            <value>hibernate/Taxes.hbm.xml</value>
            <value>hibernate/CertificateEntry.hbm.xml</value>
         </list>
      </property>
   </bean>

   <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"
      id="tm.fbi">
      <property name="sessionFactory" ref="sf.fbi" />
   </bean>
   [B]<bean id="transactionalStudentDao"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="transactionManager">
         <ref bean="tm.fbi" />
      </property>
      <property name="target">
         <bean class="HibernateEntryDao">
            <property name="sessionFactory">
               <ref local="sf.fbi" />
            </property>
         </bean>
      </property>
      <property name="transactionAttributes">
         <props>
            <prop key="*">PROPAGATION_REQUIRED</prop>
         </props>
      </property>
   </bean>
[/B]
   <bean abstract="true" class="AbstractHibernateDao"
      id="abstractHibernateDao.fbi">
      <property name="sessionFactory" ref="sf.fbi" />
   </bean>

   
   <bean class="HibernateEntryDao" id="dao.entry"
      parent="abstractHibernateDao.fbi" />


</beans>


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.