I'm running a test case which tests my application's hibernate stuff which is deployed on a Weblogic 8.1 server.
here is the setup method
private Core2HbmVisitor visitor;
private Session session;
private Transaction t;
protected void setUp() throws Exception {
Configuration config = new Configuration();
config.configure();
SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
t = session.beginTransaction();
visitor = new Core2HbmVisitor(session);
}
While doing a session.beginTransaction i get the following error.
org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:187)
at org.hibernate.transaction.JTATransaction.begin(JTATransaction.java:89)
at org.hibernate.transaction.JTATransactionFactory.beginTransaction(JTATransactionFactory.java:53)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079)
at castle.server.hbm.biz.visitor.TestCore2Hbm.setUp(TestCore2Hbm.java:25)
at junit.framework.TestCase.runBare(TestCase.java:125)
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.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: javax.transaction.SystemException: You may enlist a resource only on a server
at weblogic.transaction.internal.TransactionImpl.registerSynchronization(TransactionImpl.java:494)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:176)
... 15 more
The hibernate.cfg.xml file is as under
--------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="hibernate.jndi.url">
t3://localhost:7001
</property>
<property name="hibernate.jndi.class">
weblogic.jndi.WLInitialContextFactory
</property>
<property name="hibernate.connection.datasource">
castle/datasources/castle
</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WeblogicTransactionManagerLookup
</property>
<!-- This is required for weblogic! -->
<property name="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</property>
<!-- These are tunning properties set by Romulus after some tests.
Please don't change these values whithout talking with Romulus!!!! -->
<property name="hibernate.max_fetch_depth">5</property>
<property name="hibernate.default_batch_fetch_size">250</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<!-- cache settings -->
<property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>
<property name="hibernate.cache.use_query_cache">true</property>
<!-- dialect for Sybase -->
<property name="dialect">
org.hibernate.dialect.SybaseDialect
</property>
<property name="hibernate.show_sql">false</property>
<mapping resource="castle/DescriptionType.hbm.xml" />
<mapping resource="castle/Description.hbm.xml" />
<mapping resource="castle/DescriptionGroupType.hbm.xml" />
<mapping resource="castle/DescriptionGroup.hbm.xml" />
<mapping resource="castle/Source.hbm.xml" />
<mapping resource="castle/DataSet.hbm.xml" />
<mapping resource="castle/EditDetails.hbm.xml" />
<mapping resource="castle/CastleType.hbm.xml" />
<mapping resource="castle/cds/CdsAction.hbm.xml" />
<mapping resource="castle/cds/CdsMarketDataLabel.hbm.xml" />
<mapping resource="castle/cds/CreditDefaultSwapAsset.hbm.xml" />
<mapping resource="castle/cds/Issuer.hbm.xml" />
<mapping resource="castle/cds/MarketDataLabel.hbm.xml" />
<mapping resource="castle/cds/ReferenceObligation.hbm.xml" />
<mapping resource="castle/cds/TransactionTermSet.hbm.xml" />
<mapping resource="castle/portfolio/AssetPortfolio.hbm.xml" />
<mapping
resource="castle/portfolio/AssetPortfolioAction.hbm.xml" />
<mapping
resource="castle/portfolio/AssetPortfolioMarketDataLabel.hbm.xml" />
<mapping resource="castle/cdi/CdiAction.hbm.xml" />
<mapping resource="castle/cdi/CdiContractAction.hbm.xml" />
<mapping
resource="castle/cdi/CdiContractMarketDataLabel.hbm.xml" />
<mapping resource="castle/cdi/CdiContract.hbm.xml" />
<mapping resource="castle/cdi/CdiContractTrigger.hbm.xml" />
<mapping resource="castle/cdi/CdiContractTriggerType.hbm.xml" />
<mapping resource="castle/cdi/CdIndex.hbm.xml" />
<mapping resource="castle/cdi/CdiTrancheAction.hbm.xml" />
<mapping resource="castle/cdi/CdiTranche.hbm.xml" />
<mapping resource="castle/cdo/CdoAction.hbm.xml" />
<mapping resource="castle/cdo/CdoMarketDataLabel.hbm.xml" />
<mapping resource="castle/cdo/Cdo.hbm.xml" />
<mapping resource="castle/cdo/CdoTrancheAction.hbm.xml" />
<mapping resource="castle/cdo/CdoTranche.hbm.xml" />
</session-factory>
</hibernate-configuration>
Pl let me know if anyone has faced an issue like this.