-->
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: Transaction and Session [HibernateException: createCriteria]
PostPosted: Thu Apr 01, 2010 10:09 pm 
Newbie

Joined: Thu Apr 01, 2010 2:22 am
Posts: 4
Hi,

JBoss 4.0.5
Hibernate 3.0
Spring 2.5
Oracle 10g
Cache : EhCache

In Spring Bean, we are creating SessionFactory as below
Code:
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref local="dataSource" />
      </property>
      <property name="configLocation">
         <value>classpath:/hibernate.cfg.xml</value>
      </property>
</bean>


In Session Factory Config, I have changed Transaction from JBoss CMT to JDBC as below
Code:
   <session-factory>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
      
      <!-- <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
       -->
      <property name="hibernate.current_session_context_class">thread</property>
      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
      <property name="hibernate.show_sql">false</property>
      <property name="hibernate.connection.release_mode">auto</property>

      <!-- 2nd level caching -->
      <property name="hibernate.cache.provider_class">
         org.hibernate.cache.EhCacheProvider
      </property>
      <property name="hibernate.cache.use_query_cache">true</property>
</session-factory>


1) I need to commit as Unit of Work
2) Using the same DataSource JBoss AS has.
3) Have to use Cache

Now i got the below error.
Code:
org.hibernate.HibernateException: createCriteria is not valid without active transaction
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:297)
   at $Proxy69.createCriteria(Unknown Source)



Need to change in Configuration?


Top
 Profile  
 
 Post subject: Re: Transaction and Session [HibernateException: createCriteria]
PostPosted: Fri Apr 02, 2010 2:57 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
As you don't work with no transaction manager anymore in this configuration,
a transaction is not started anymore with calling userTransaction.begin()
(probably this does absolute nothing if not specifying any transaction manager lookup class)
You must start the transaction like following before you create any query:

Code:
Session session = sf.getCurrentSession();
/// userTransaction.begin() // does nothing if no transaction manager lookup class specified
session.beginTransaction();
Query q = session.createQuery("...");


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.