Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDBC commits transaction on closed connection

kubaComarJan 9 2014 — edited Oct 15 2014

Hi,

I have a problem with Oracle JDBC. When during inserting data to DB unexcpected disconnect occurs part of data is commited.

I found information that driver do implicit COMMIT on trunsaction on close() if cmommit for rollback was not called.

Is there any solution to this? Explicit calling rollback in finally block doesn't work. I had scenatio:

0. I try to insert 100 objects.

1. 51st insert failed because closed connection.

2. I try do rollback.

3. Rollback fails due to closed connection.

4. In DB I have 50 objects.

Code:

final StatelessSession session = sessionFactory.openStatelessSession();

final Transaction tr = session.beginTransaction();

try {

    //DO SOME INSERTS

    tr.commit();

} catch (Exception e) {

    try {

        tr.rollback();

    } catch (Exception e) {

        log.error("Exception during transaction rollback", e);

    }

    throw new MyException(e);

} finally {

    session.close()

}

And  Spring configuration:

<bean id="sessionFactory"

  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

  <property name="packagesToScan">

  <list>

  <value>com.comarch.brokerage.cbs.kernel.common.domain</value>

  <value>com.comarch.brokerage.workflow.spaces.mirror</value>

  <!--value>com.comarch.cbs.ddd.**.*</value -->

  </list>

  </property>

  <property name="hibernateProperties">

  <props>

  <prop key="hibernate.connection.username">${dataSource.username}</prop>

  <prop key="hibernate.connection.password">${dataSource.password}</prop>

  <prop key="hibernate.connection.url">${dataSource.url}</prop>

  <prop key="hibernate.connection.driver_class">${dataSource.driverClassName}</prop>

  <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>

  <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>

  <prop key="hibernate.cache.use_second_level_cache">false</prop>

  <prop key="hibernate.cache.use_query_cache">false</prop>

  <prop key="hibernate.globally_quoted_identifiers">true</prop>

  <prop key="javax.persistence.validation.mode">none</prop>

  <prop key="hibernate.c3p0.max_size">${dataSource.maxActive}</prop>

  <prop key="hibernate.c3p0.min_size">1</prop>

  <prop key="hibernate.c3p0.timeout">5000</prop>

  <prop key="hibernate.c3p0.max_statements">500</prop>

  <prop key="hibernate.jdbc.batch_size">0</prop>

  <prop key="hibernate.connection.defaultExecuteBatch">${dataSource.oracleBatchSize}</prop>

  <prop key="hibernate.connection.autocommit">false</prop>

  </props>

  </property>

  </bean>

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 12 2014
Added on Jan 9 2014
12 comments
5,089 views