-->
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.  [ 1 post ] 
Author Message
 Post subject: Disabling autocommit when using JNDI Datasource
PostPosted: Wed Oct 25, 2006 8:37 am 
Newbie

Joined: Tue Apr 11, 2006 5:55 am
Posts: 4
Hi,

I am having problems disabling autocommit for my datasource when i'm using a JNDI DataSource.
There is a paragraph in the documentation that says ;

"
JDBC connections obtained from a JNDI datasource will automatically participate in the container-managed transactions of the application server.

Arbitrary connection properties may be given by prepending "hibernate.connection" to the property name. For example, you may specify a charSet using hibernate.connection.charSet.
"


Am I right in concluding that any hibernate.connection.* properties i set in this case will be ignored?

My hibernate config looks like this, and it definately feels like it does get ignored;
Code:
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="show_sql">true</property>
    <property name="hibernate.connection.datasource">jdbc/MyDataSource</property>
    <property name="hibernate.cache.provider_class">net.sf.hibernate.cache.EhCacheProvider</property>
   <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
   <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
   <property name="hibernate.connection.autocommit">false</property>
   <property name="hibernate.connection.defaultAutoCommit">false</property>
   <mapping resource="com/test/framework/persistence/Default.hbm.xml" />   
</session-factory>
</hibernate-configuration>


With these settings, rows are still inserted in the database when this code is executed;

Code:
     
  try {
            getSession().openSession();
            getSession().saveOrUpdate(to);
            getSession().flush();
        } catch (HibernateException he) {
            final String msg = "HibernateException caught in BaseObjectStore.save()";
            log.error(msg, he);
            throw new SystemException(FrameworkExceptions.CONTEXT,
                                      FrameworkExceptions.PERSISTENCE_ERROR,
                                      msg,
                                      he);
        } finally {
            getSession().close();
        }



When i create a basic JUnit test and configure my DataSource as a normal non DataSource DS like this (Spring bean configuration)
Code:
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="SCDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@DBServer:1521:TestSchema" />
        <property name="username" value="scott" />
        <property name="password" value="tiger" />
        <property name="defaultAutoCommit" value="false" />
         
    </bean>


I get the exact behavious I am after - no insert statement has been run.

I can see 2 reasons why the first approach ios not working
1. I am setting the wrong properties. If I am, i am terribly sorry for wasting your time, please tell me what the proper property names are (I cannot find ant other references to autocommit than hibernate.connection.autocommit)
2. I have to set the autocommit property in my DataSource (like the documentation kind of implies). If so, does anyone know how to configure this on Weblogic/Oracle8.1 (I am not managing to set that property)

The obvious question that people are about to ask is ' why the heck are you trying to do this?'. The reason is I want to be able to run unittests that check the integrity of my components, and everything i save is cached, so not writing it will not affect the integrity. Rather than writing hundreds of Dummy implementation of the database layer, i'd like to be able to switch inserts off in my UnitTest config, and not have to set up a completely different DataSource config than the live config..

Appreciate any help..

Regards

/Johan

Hibernate version: 3.1.2

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: Oracle 8.1


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.