Announcement Announcement Module
Collapse
No announcement yet.
transaction rollbacks, but a record is inserted, why? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • transaction rollbacks, but a record is inserted, why?

    I use Spring and Hibernate in my project.
    In a transaction I want to insert two records to two different tables. When I insert the second record, I set a large value for a colum. From the output of my application, I can see the transaction rollbacked, but the first record was inserted to database. Can anybody help me, thanks?My config file as follows:
    ---------------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <!-- ========================= GENERAL DEFINITIONS ========================= -->
    <!-- Configurer that replaces ${...} placeholders with values from properties files -->
    <!-- (in this case, mail and JDBC related properties) -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>database.properties</value>
    </list>
    </property>
    </bean>
    <!-- ========================= RESOURCE DEFINITIONS ========================= -->
    <!-- Local DataSource that refers to a combined database -->
    <!-- (see dataAccessContext-jta.xml for an alternative) -->
    <!-- The placeholders are resolved from jdbc.properties through -->
    <!-- the PropertyPlaceholderConfigurer in applicationContext.xml -->
    <!--
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>${jdbc.driverClassName}</value>
    </property>
    <property name="url">
    <value>${jdbc.url}</value>
    </property>
    <property name="username">
    <value>${jdbc.username}</value>
    </property>
    <property name="password">
    <value>${jdbc.password}</value>
    </property>
    </bean>
    -->
    <!-- Transaction manager for a single JDBC DataSource -->
    <!-- (see dataAccessContext-jta.xml for an alternative) -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    <property name="rollbackOnCommitFailure">
    <value>true</value>
    </property>
    </bean>
    <!-- ==============================================data base config====================================== -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>${hibernate.connection.driver_class}</value>
    </property>
    <property name="url">
    <value>${hibernate.connection.url}</value>
    </property>
    <property name="username">
    <value>${hibernate.connection.username}</value>
    </property>
    <property name="password">
    <value>${hibernate.connection.password}</value>
    </property>
    </bean>
    <!-- sessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/travelsky/opack/domain/order/Order.hbm.xml</value>
    <value>com/travelsky/opack/domain/order/HotelDetail.hbm.xml</value>
    <value>com/travelsky/opack/domain/order/FlightInfo.hbm.xml</value>
    <value>com/travelsky/opack/domain/order/Traveller.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <!--
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.H SQLDialect</prop>
    -->
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>
    <!-- orderManager -->
    <bean id="orderManager" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref local="transactionManager"/>
    </property>
    <property name="target">
    <ref local="orderManagerTarget"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    <!-- orderManagerTarget -->
    <bean id="orderManagerTarget" class="com.travelsky.opack.manager.OrderManagerImp l">
    <property name="orderDAO">
    <ref local="orderDAO"/>
    </property>
    <property name="hotelDetailDAO">
    <ref local="hotelDetailDAO"/>
    </property>
    <property name="flightInfoDAO">
    <ref local="flightInfoDAO"/>
    </property>
    <property name="travellerDAO">
    <ref local="travellerDAO"/>
    </property>
    </bean>
    <!-- order dao -->
    <bean id="orderDAO" class="com.travelsky.opack.domain.order.dao.hbimpl .OrderDAOImpl">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>
    <bean id="hotelDetailDAO" class="com.travelsky.opack.domain.order.dao.hbimpl .HotelDetailDAOImpl">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>
    <bean id="flightInfoDAO" class="com.travelsky.opack.domain.order.dao.hbimpl .FlightInfoDAOImpl">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>
    <bean id="travellerDAO" class="com.travelsky.opack.domain.order.dao.hbimpl .TravellerDAOImpl">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>
    <!-- ordertest -->
    <bean id="orderTest" class="test.travelsky.opentrans.core.OrderTest1">
    <property name="orderDAO">
    <ref local="orderDAO"/>
    </property>
    <property name="hotelDetailDAO">
    <ref local="hotelDetailDAO"/>
    </property>
    <property name="flightInfoDAO">
    <ref local="flightInfoDAO"/>
    </property>
    <property name="travellerDAO">
    <ref local="travellerDAO"/>
    </property>
    </bean>
    </beans>


    My application outputs:
    ---------------------------------------------------------------
    2004-11-19 12:59:11,695 DEBUG [org.springframework.transaction.interceptor.Transa ctionInterceptor] - <Getting transaction for method 'insertTravellerFlight2Order' in class [com.travelsky.opack.manager.OrderManager]>

    2004-11-19 12:59:11,695 INFO [org.springframework.jdbc.datasource.DataSourceTran sactionObject] - <JDBC 3.0 Savepoint class is available>

    2004-11-19 12:59:11,825 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Bound value [org.springframework.jdbc.datasource.ConnectionHold er@57e787] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@f8395f] to thread [main]>

    2004-11-19 12:59:11,825 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Initializing transaction synchronization>

    2004-11-19 12:59:11,825 DEBUG [com.travelsky.opack.manager.OrderManagerImpl] - <--begin insert traveller and flight to order-->

    2004-11-19 12:59:11,855 DEBUG [com.travelsky.opack.manager.OrderManagerImpl] - <--begin insert flight to order -->

    2004-11-19 12:59:11,995 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Bound value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] to thread [main]>

    2004-11-19 12:59:12,015 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    2004-11-19 12:59:12,046 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    Hibernate: insert into OP_ORDER_FLTINFO (ITIORDER, FLTNUMBER, CABIN, STARTCITY, DESTCITY, TAKEOFFTIME, LANDTIME, AIRLINE, MEMO, PRODORDERID, FLTITIINFOID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

    2004-11-19 12:59:12,286 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    2004-11-19 12:59:12,286 DEBUG [com.travelsky.opack.manager.OrderManagerImpl] - <--insert flight to order ok-->

    2004-11-19 12:59:12,286 DEBUG [com.travelsky.opack.manager.OrderManagerImpl] - <--begin insert traveller to order-->

    2004-11-19 12:59:12,286 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    2004-11-19 12:59:12,306 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    2004-11-19 12:59:12,306 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    Hibernate: insert into OP_ORDER_TRAVELER (GUESTIDINFO, GUESTNAME, GUESTTYPE, GUESTPNRID, TKTNUMBER, PRODORDERID, GUESTID) values (?, ?, ?, ?, ?, ?, ?)

    2004-11-19 12:59:12,526 WARN [net.sf.hibernate.util.JDBCExceptionReporter] - <SQL Error: 1401, SQLState: 23000>

    2004-11-19 12:59:12,526 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <ORA-01401: inserted value too large for column
    >

    2004-11-19 12:59:12,536 WARN [net.sf.hibernate.util.JDBCExceptionReporter] - <SQL Error: 1401, SQLState: 23000>

    2004-11-19 12:59:12,536 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <ORA-01401: inserted value too large for column
    >

    2004-11-19 12:59:12,576 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <Could not execute JDBC batch update>

    java.sql.SQLException: ORA-01401: inserted value too large for column


    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:168)

    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:2 08)

    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)

    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol .java:1405)

    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TT C7Protocol.java:822)

    at oracle.jdbc.driver.OracleStatement.executeNonQuery (OracleStatement.java:1446)

    at oracle.jdbc.driver.OracleStatement.doExecuteOther( OracleStatement.java:1371)

    at oracle.jdbc.driver.OraclePreparedStatement.execute Batch(OraclePreparedStatement.java:2883)

    at net.sf.hibernate.impl.BatchingBatcher.doExecuteBat ch(BatchingBatcher.java:54)

    at net.sf.hibernate.impl.BatcherImpl.executeBatch(Bat cherImpl.java:126)

    at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2421)

    at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2371)

    at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2240)

    at org.springframework.orm.hibernate.HibernateTemplat e$20.doInHibernate(HibernateTemplate.java:416)

    at org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:200)

    at org.springframework.orm.hibernate.HibernateTemplat e.flush(HibernateTemplate.java:414)

    at com.travelsky.opentrans.persistence.HibernateBaseD AO.createObject(HibernateBaseDAO.java:27)

    at com.travelsky.opack.domain.order.dao.hbimpl.Travel lerDAOImpl.createTraveller(TravellerDAOImpl.java:2 7)

    at com.travelsky.opack.manager.OrderManagerImpl.inser tTravellerFlight2Order(OrderManagerImpl.java:199)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:324)

    at org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:61 )

    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:149)

    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :116)

    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)

    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)

    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:152)

    at $Proxy0.insertTravellerFlight2Order(Unknown Source)

    at test.travelsky.opentrans.core.OrderManagerTest.ins ertFlightTraveller(OrderManagerTest.java:57)

    at test.travelsky.opentrans.core.OrderManagerTest.mai n(OrderManagerTest.java:65)

    2004-11-19 12:59:12,596 ERROR [net.sf.hibernate.impl.SessionImpl] - <Could not synchronize database state with session>

    net.sf.hibernate.JDBCException: Could not execute JDBC batch update

    at net.sf.hibernate.impl.BatcherImpl.executeBatch(Bat cherImpl.java:133)

    at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2421)

    at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2371)

    at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2240)

    at org.springframework.orm.hibernate.HibernateTemplat e$20.doInHibernate(HibernateTemplate.java:416)

    at org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:200)

    at org.springframework.orm.hibernate.HibernateTemplat e.flush(HibernateTemplate.java:414)

    at com.travelsky.opentrans.persistence.HibernateBaseD AO.createObject(HibernateBaseDAO.java:27)

    at com.travelsky.opack.domain.order.dao.hbimpl.Travel lerDAOImpl.createTraveller(TravellerDAOImpl.java:2 7)

    at com.travelsky.opack.manager.OrderManagerImpl.inser tTravellerFlight2Order(OrderManagerImpl.java:199)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:324)

    at org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:61 )

    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:149)

    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :116)

    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)

    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)

    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:152)

    at $Proxy0.insertTravellerFlight2Order(Unknown Source)

    at test.travelsky.opentrans.core.OrderManagerTest.ins ertFlightTraveller(OrderManagerTest.java:57)

    at test.travelsky.opentrans.core.OrderManagerTest.mai n(OrderManagerTest.java:65)

    Caused by: java.sql.SQLException: ORA-01401: inserted value too large for column


    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBE rror.java:168)

    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:2 08)

    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)

    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol .java:1405)

    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TT C7Protocol.java:822)

    at oracle.jdbc.driver.OracleStatement.executeNonQuery (OracleStatement.java:1446)

    at oracle.jdbc.driver.OracleStatement.doExecuteOther( OracleStatement.java:1371)

    at oracle.jdbc.driver.OraclePreparedStatement.execute Batch(OraclePreparedStatement.java:2883)

    at net.sf.hibernate.impl.BatchingBatcher.doExecuteBat ch(BatchingBatcher.java:54)

    at net.sf.hibernate.impl.BatcherImpl.executeBatch(Bat cherImpl.java:126)

    ... 22 more

    2004-11-19 12:59:12,636 WARN [org.springframework.jdbc.support.SQLErrorCodeSQLEx ceptionTranslator] - <Unable to translate SQLException with errorCode '1401', will now try the fallback translator>

    2004-11-19 12:59:12,636 INFO [org.springframework.jdbc.support.SQLStateSQLExcept ionTranslator] - <Translating SQLException with SQLState '23000' and errorCode '1401' and message [ORA-01401: inserted value too large for column
    ]; SQL was [] for task [Hibernate operation]>

    2004-11-19 12:59:12,636 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] bound to thread [main]>

    2004-11-19 12:59:12,716 DEBUG [org.springframework.transaction.interceptor.RuleBa sedTransactionAttribute] - <Applying rules to determine whether transaction should rollback on org.springframework.dao.DataIntegrityViolationExce ption: (Hibernate operation): data integrity violated by SQL ''; nested exception is java.sql.SQLException: ORA-01401: inserted value too large for column
    >

    2004-11-19 12:59:12,716 DEBUG [org.springframework.transaction.interceptor.RuleBa sedTransactionAttribute] - <Winning rollback rule is: RollbackRule with pattern 'Exception'>

    2004-11-19 12:59:12,747 DEBUG [org.springframework.transaction.interceptor.Transa ctionInterceptor] - <Invoking rollback for transaction on method 'insertTravellerFlight2Order' in class [com.travelsky.opack.manager.OrderManager] due to throwable [org.springframework.dao.DataIntegrityViolationExce ption: (Hibernate operation): data integrity violated by SQL ''; nested exception is java.sql.SQLException: ORA-01401: inserted value too large for column
    ]>

    2004-11-19 12:59:12,747 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Removed value [org.springframework.orm.hibernate.SessionHolder@5a ebd9] for key [net.sf.hibernate.impl.SessionFactoryImpl@1f1bd98] from thread [main]>

    2004-11-19 12:59:12,807 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Clearing transaction synchronization>

    2004-11-19 12:59:12,807 DEBUG [org.springframework.transaction.support.Transactio nSynchronizationManager] - <Removed value [org.springframework.jdbc.datasource.ConnectionHold er@57e787] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@f8395f] from thread [main]>

  • #2
    You should be using HibernateTransactionManager instead of DataSourceTransactionManager.

    Comment

    Working...
    X