Hi all,
I have an application that runs fine within an application server, with
Spring and Hibernate. But if I want to test a method with JUnit I always get
this Exception:

[CODE]
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:300)
        at $Proxy0.getCurrentSession(Unknown Source)
        at
org.fornax.cartridges.sculptor.framework.serviceimpl.EnableDeletedObjectsFilterAdvice.invoke(EnableDeletedObjectsFilterAdvice.java:38)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.fornax.cartridges.sculptor.framework.errorhandling.ServiceContextStoreAdvice.invoke(ServiceContextStoreAdvice.java:39)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.fornax.cartridges.sculptor.framework.errorhandling.ReattachHibernateObjectsAdvice.invoke(ReattachHibernateObjectsAdvice.java:49)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy77.findCarByObjectId(Unknown Source)
        at
de.mypackage.backend.fault.serviceapi.CarServiceTest.testFindCarByObjectId(CarServiceTest.java:53)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[/CODE]

I've read through many posts from several forums, but none of the solutions
offered there did solve my problem. My applicationContext-test.xml only
imports some other xml files, therefore here the one I think that is crucial
(SessionFactory-test.xml):

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

<beans ...namespaces omitted...>  
  <bean id="hsqldbDataSource"
class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName"> 
      <value>org.hsqldb.jdbcDriver</value> 
    </property>  
    <property name="url"> 
      <value>jdbc:hsqldb:mem:mitgas</value> 
    </property>  
    <property name="username"> 
      <value>sa</value> 
    </property>  
    <property name="password"> 
      <value/> 
    </property> 
  </bean>  
  <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="dataSource"> 
      <ref bean="hsqldbDataSource"/> 
    </property>  
    <property name="hibernateProperties"> 
      <props> 
        <prop
key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>  
        <prop key="hibernate.hbm2ddl.auto">create-drop</prop>  
        <prop key="hibernate.show_sql">true</prop>  
        <prop key="hibernate.query.substitutions">true 1, false 0</prop>  
        <prop key="hibernate.cache.use_query_cache">true</prop>  
        <prop
key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 
      </props> 
    </property>  
    <property name="mappingResources"> 
      <list> 
        ... list of entities ...
      </list> 
    </property>  
    <property name="entityInterceptor"> 
      <ref bean="auditInterceptor"/> 
    </property> 
  </bean>  
  <bean id="auditInterceptor"
class="org.fornax.cartridges.sculptor.framework.domain.AuditInterceptor"/> 
[/CODE]

Another Bean definition for the Transaction handling is as follows:

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

<beans  ...namespaces omitted...>
    
<!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean
below) -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
        <tx:attributes>
<!-- all methods starting with 'find' are read-only -->
            <tx:method name="find*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>


<!-- ensure that the above transactional advice runs for any execution
of an operation defined by the CarService interface -->
    <aop:config>
        <aop:pointcut id="carServiceOperation" expression="execution(*
de.mypackage.*Service.*(..))"/>
        <aop:advisor advice-ref="txAdvice"
pointcut-ref="carServiceOperation"/>
    </aop:config>

    <bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
</beans>
[/CODE]

I think, this configuration cares for the right transaction handling, but
obviously it isn't. Can anybody out there tell me what's wrong?

TIA,
Ralf.
-- 
View this message in context: 
http://www.nabble.com/HibernateException-while-running-JUnit-tests-tp21950045s17564p21950045.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Fornax-developer mailing list
Fornax-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Reply via email to