Hello,
I'm using JUnit to unit test my application, so I run it without a JTA.
I would like to use getCurrentSession, by binding transaction managment to thread context, as described in the docs, but it keeps throwing a 'No TransactionManagerLookup specified' exception.
I have no problems if I use openSession instead.
Here are the configuration details:
Hibernate version:3.2
hibernate.cfg.xml:
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost/dbName</property>
<property name="connection.instance">SQLEXPRESS</property>
<property name="connection.username">USER</property>
<property name="connection.password">PWD</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</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="path/to/mapFile.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Language").list();
session.getTransaction().commit();
return result;
Full stack trace of any exception that occurs:
org.hibernate.HibernateException: No TransactionManagerLookup specified
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:503)
at com.modelity.ratingmodel.hibernate.LanguageManager.getAllLanguages(LanguageManager.java:13)
at unittest.com.modelity.ratingmodel.hibernate.TestLanguageManager.testGetAllLanguages(TestLanguageManager.java:13)
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: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.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)
Name and version of the database you are using:
SQL Server 2005
Debug level Hibernate log excerpt:
log4j:WARN Continuable parsing error 5 and column 87
log4j:WARN Document root element "log4j:configuration", must match DOCTYPE root "null".
log4j:WARN Continuable parsing error 5 and column 87
log4j:WARN Document is invalid: no grammar found.
0 [main] INFO cfg.Environment - Hibernate 3.0.5
0 [main] INFO cfg.Environment - hibernate.properties not found
0 [main] INFO cfg.Environment - using CGLIB reflection optimizer
0 [main] INFO cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
78 [main] INFO cfg.Configuration - configuring from resource: /hibernate.cfg.xml
78 [main] INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml
281 [main] INFO cfg.Configuration - Mapping resource: path/to/class/Language.hbm.xml
421 [main] INFO cfg.HbmBinder - Mapping class: path.to.class.Language -> languages
453 [main] INFO cfg.Configuration - Configured SessionFactory: null
453 [main] INFO cfg.Configuration - processing extends queue
453 [main] INFO cfg.Configuration - processing collection mappings
453 [main] INFO cfg.Configuration - processing association property references
453 [main] INFO cfg.Configuration - processing foreign key constraints
546 [main] INFO connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
546 [main] INFO connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
546 [main] INFO connection.DriverManagerConnectionProvider - autocommit mode: false
562 [main] INFO connection.DriverManagerConnectionProvider - using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://localhost/DBName
562 [main] INFO connection.DriverManagerConnectionProvider - connection properties: {instance=SQLEXPRESS, user=USER, password=****}
812 [main] INFO cfg.SettingsFactory - RDBMS: Microsoft SQL Server, version: 09.00.2047
812 [main] INFO cfg.SettingsFactory - JDBC driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase, version: 1.2
828 [main] INFO dialect.Dialect - Using dialect: org.hibernate.dialect.SQLServerDialect
843 [main] INFO transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
843 [main] INFO transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
843 [main] INFO cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
843 [main] INFO cfg.SettingsFactory - Automatic session close at end of transaction: disabled
843 [main] INFO cfg.SettingsFactory - Scrollable result sets: enabled
843 [main] INFO cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
843 [main] INFO cfg.SettingsFactory - Connection release mode: null
843 [main] INFO cfg.SettingsFactory - Default batch fetch size: 1
843 [main] INFO cfg.SettingsFactory - Generate SQL with comments: disabled
843 [main] INFO cfg.SettingsFactory - Order SQL updates by primary key: disabled
843 [main] INFO cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
859 [main] INFO ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
859 [main] INFO cfg.SettingsFactory - Query language substitutions: {}
859 [main] INFO cfg.SettingsFactory - Second-level cache: enabled
859 [main] INFO cfg.SettingsFactory - Query cache: disabled
859 [main] INFO cfg.SettingsFactory - Cache provider: org.hibernate.cache.NoCacheProvider
859 [main] INFO cfg.SettingsFactory - Optimize cache for minimal puts: disabled
859 [main] INFO cfg.SettingsFactory - Structured second-level cache entries: disabled
859 [main] INFO cfg.SettingsFactory - Echoing all SQL to stdout
859 [main] INFO cfg.SettingsFactory - Statistics: disabled
859 [main] INFO cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
859 [main] INFO cfg.SettingsFactory - Default entity-mode: pojo
1015 [main] INFO impl.SessionFactoryImpl - building session factory
1375 [main] INFO impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
1375 [main] INFO impl.SessionFactoryImpl - Checking 0 named queries
Thanks!
Vitaliy
|