Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Spring IOC + hibernate

  1. #11
    Join Date
    Mar 2007
    Posts
    21

    Default

    karldmoore : EMIDKI (Excuse me, I didn't know it)

    Rick Evans : hi Rick, I didn't know it but as you can see in my hibernate.cfg.xml file, I've defined a "current_session_context_class" but the problem still remains. Is it correct ?

    The hibernate.cfg.xml file :
    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    
        <session-factory>
            <!--MySQL JDBC Driver connection -->
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="connection.url">jdbc:mysql://localhost/maDB</property>
            <property name="connection.username">root</property>
            <property name="connection.password">test</property>
            <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
    
            <!-- JDBC connection pool (use the built-in) -->
            <property name="connection.pool_size">1</property>
    
            <!-- Enable Hibernate's automatic session context management -->
            <property name="current_session_context_class">org.hibernate.context.JTASessionContext</property>
    
            <!-- Disable the second-level cache  -->
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    
            <!-- Echo all executed SQL to stdout -->
            <property name="show_sql">true</property>
    
            <mapping resource="com/company/countryApp/bo/Country.hbm.xml"/>
    
        </session-factory>
    </hibernate-configuration>
    The full stack trace :
    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:299)
    	at $Proxy0.getCurrentSession(Unknown Source)
    	at com.company.countryApp.junits.CountryTestUnit.testSaveCountry(CountryTestUnit.java:32)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    However, I'll follow your recommendations for the use of HibernateTemplate instead of working directly with the SessionFactory…

  2. #12
    Join Date
    Aug 2007
    Posts
    9

    Default

    sixtiesman, i'm having the same problem trying to use plain hibernate3 api in my daos, and found no solution yet. i raised this question again at

    http://forum.springframework.org/showthread.php?t=42297

    i think it's important to continue this issue because i've seen various references to this same problem, which leads me to think if the spring documentation might be missing something.

  3. #13
    Join Date
    Mar 2007
    Posts
    21

    Default

    hi dazen6

    I'm not a J2EE expert but I never managed to implement the "plain hibernate3 api" in my DAO's. I've not been helped (I'm a student and I did it during a traning period) and I gave up this idea after hours !

    The problem only disappeared when I used the "HibernateTemplate" class instead of the "SessionFactory" class provided by Hibernate and I handled the transactions the declarative way.

    I really advise you to do this but I really would be curious to know how we can solve this an other way.

    good luck dazen6 !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •