Announcement Announcement Module
Collapse
No announcement yet.
A question about transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A question about transactions

    Hi everyone
    I have a qustion about transactions.I'm using Spring in conjuntion with Hibernate and Oracle 9i.
    I'm using HibernateTransactionManager
    Code:
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <bean id="dataTypeDao" class="dao.hibernate.DataTypeDao">
    		<property name="sessionFactory"><ref bean="sessionFactory"/></property>
    	</bean>
    I have ommited session factory configuration because it's trivial.


    a tx proxy template
    Code:
    <bean id="txProxyTemplate" abstract="true"
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager"><ref bean="transactionManager"/></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    and finally
    Code:
    <bean id="dataTypeBL" parent="txProxyTemplate" >	
    		<property name="target">
    			<bean class="service.impl.DataTypeBL">
    				<property name="dataTypeDao">
    					<ref bean="dataTypeDao" />
    				</property>
    			</bean>
    		</property>
    	</bean>
    Now to my problem.
    I've made a form through which i can enter information about DataType object which has 'name' among other attributes that has a unique constraint in db. When I enter a new object with a name that already exists and try to save a proper exception is thrown which I can process properly. Problem occurs when i try to save again.
    Here is stack trace
    Code:
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException
    	message : Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [model.DataType#49]; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [model.DataType#49]
    org.hibernate.StaleObjectStateException
    	message : Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [model.DataType#49]
    2005-11-03 14:14:37,537 INFO  [STDOUT] 
    false
    2005-11-03 14:14:37,537 DEBUG [org.springframework.web.servlet.DispatcherServlet] HandlerExceptionResolver returned ModelAndView [ModelAndView: reference to view with name 'error'; model is {error=Error executing operation.}] for exception
    2005-11-03 14:14:37,537 WARN  [org.springframework.web.servlet.DispatcherServlet] Handler execution resulted in exception - forwarding to resolved error view
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [model.DataType#49]; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [model.DataType#49]
    org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [model.DataType#49]
    Is there a way to solve this in a declarative manner easily

  • #2
    This is a Hibernate optimistic locking issue and AFAICT not related to Spring's transaction management. If you post your Java code/hibernate mapping file maybe someone wll spot the problem.

    Comment


    • #3
      See the Hibernate FAQ - http://www.hibernate.org/5.html (top of the page).

      Comment


      • #4
        Here is the mapping file
        Code:
        <?xml version="1.0"?>
        <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
        <hibernate-mapping>
        <!-- 
                Auto-generated mapping file from
                the hibernate.org cfg2hbm engine
        -->
            <class name="model.DataType" table="DATATYPE" discriminator-value="0">
                <id name="dataTypeId" type="long" >
                    <column name="DATATYPEID"  />
                    <generator class="sequence" >
                    	<param name="sequence">DATATYPEID_sq</param>
                    </generator>
                </id>
        		<discriminator column="DATATYPETYPEID" type="long"/>
        		
        		<version name="beanVersion"
        			column="version_"
        			type="long" />
        		
        		<property name="name" >
                    <column name="NAME" not-null="true" />
                </property>	
                       
                <property name="description">
                    <column name="DESCRIPTION" />
                </property>
        		<property name="dataTypeTypeId" insert="false" update="false">
                    <column name="dataTypeTypeId" />
                </property>
        		
        		<subclass name="model.DataTypeEnumerated" discriminator-value="1">
        			<join table="DataTypeEnumerated">
        				<key column="DataTypeEnumeratedId" />
        			</join>
        		</subclass>
            </class>
        </hibernate-mapping>

        Comment


        • #5
          HibernateOptimisticLockingFailureException

          hi,
          im new to spring.im using cocoon,hibernate and spring in my sample application.In this specific HibernateDAO class im using this

          this.getHibernateTemplate().saveOrUpdate(country);

          instead of save and update methods.
          But i've run time error like this..

          Error:org.springframework.orm.hibernate3.HibernateOptimi sticLockingFailureException: B
          atch update returned unexpected row count from update [0]; actual row count: 0;
          expected: 1; nested exception is org.hibernate.StaleStateException: Batch update
          returned unexpected row count from update [0]; actual row count: 0; expected: 1

          Caused by: org.hibernate.StaleStateException: Batch update returned unexpected r
          ow count from update [0]; actual row count: 0; expected: 1

          Anybody help me to overcome this problem..
          thanx in advance..

          Comment

          Working...
          X