Announcement Announcement Module
Collapse
No announcement yet.
hibernate + version & txn mgmt =no StaleObjectStateExcep Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hibernate + version & txn mgmt =no StaleObjectStateExcep

    We have successfully used Hibernate and versioning in our DAO tier to provide optimistic locking. This works great when exposed up through our service tier to the UI tier.

    Yet when we wrap the service tier with transaction management (using either Hibernate txn mgmt or WebLogic JTA txn mgmt) the org.hibernate.StaleObjectStateException is no longer thrown - instead the stale update is committed to the db. It would appear that the version passed down from the UI tier is ignored, and the version on the db instance is instead used in the where clause.

    Has anyone else hit this, or have thoughts as to why adding txn mgmt stops optimistic locking from working? One thing that stands out when testing w/ wo/ txn mgmt is that w/ txn mgmt we see the following debug statement:
    Code:
    DEBUG persister.entity.BasicEntityPersister - org.sample.domain.User.version is dirty
    Where version is the version column.

    Regards
    Martin

  • #2
    Spring bean follows...
    Code:
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
            
            <!-- WebLogic transaction manager -->
    
            <bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
            
            <bean id="adminManagerTransactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
                    <property name="properties">
                            <props>
                                    <prop key="lookupUser">
                                            PROPAGATION_SUPPORTS,
                                            ISOLATION_READ_COMMITTED,
                                            readOnly
                                    </prop>
                                    <prop key="updateUser">                        
                                            PROPAGATION_REQUIRED,
                                            ISOLATION_SERIALIZABLE,
                                            -java.lang.Exception,
                                            -com.sample.domain.exceptions.StaleRecordNotUpdatedException
                                    </prop>
                            </props>
                    </property>
            </bean>
    
            <!-- defining abstract transaction proxies, these are the parents -->
            
            <bean id="adminManagerAbstractTxDefinition" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true">
                    <property name="transactionManager"><ref bean="transactionManager"/></property>
                    <property name="transactionAttributeSource"><ref bean="adminManagerTransactionAttributeSource"/></property>
            </bean>        
            
            <bean id="adminManagerCounter" class="com.sample.frameworks.throttle.CounterDetailsImpl" singleton="false">
                    <constructor-arg index="0" value="ASD_USER_MANAGER_COUNTER" />
                    <property name="limit" value="3"/>
                    <property name="maxInterval" value="300000"/>
                    <property name="logErrorCount" value="1000"/>
            </bean>
    
            <bean id="adminManagerThrottleAdvice" class="com.sample.frameworks.throttle.ThrottleInterceptorImpl">
                    <property name="throttler"><ref bean="inflightCounter"/></property>
                    <property name="counter"><ref bean="adminManagerCounter"/></property>
            </bean>
    
            <bean id="adminManagerThrottleAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
                    <property name="mappedNames"><list><value>registerContact</value><value>updateContact</value></list></property>
                    <property name="advice"><ref bean="adminManagerThrottleAdvice"/></property>
            </bean>
    
            <!-- at last, the services -->
                    
            <bean id="throttledAdminManager" class="org.springframework.aop.framework.ProxyFactoryBean">
                    <property name="proxyInterfaces"><value>com.sample.service.AdminManager</value></property>
                    <property name="interceptorNames"><list><value>adminManagerThrottleAdvisor</value></list></property>
                    <property name="target">
                            <bean name="standardAdminManager" parent="adminManagerAbstractTxDefinition">
                                    <property name="target">
                                            <bean class="com.sample.service.AdminManagerAuditorImpl" init-method="init">
                                                    <property name="adminManager">
                                                            <bean class="com.sample.service.AdminManagerImpl">
                                                                    <property name="userDao"><ref bean="hibernateUserDao"/></property>
                                                                    <property name="identityManager"><ref bean="identityManager"/></property>
                                                            </bean>                                        
                                                    </property>
                                                    <property name="auditor"><ref bean="hibernateAuditDao"/></property>
                                            </bean>                        
                                    </property>
                            </bean>
                    </property>
            </bean>
    </beans>

    Comment


    • #3
      Hibernate concurrency problem

      Hi I have the same issue. I

      1) Load my domain object
      2) Updates the modified fields
      3) Updates the version from the updated domain object (this trigger out the concurrency updates)

      and save.

      In my case the domain saves without the problem even in two concurrency updates

      Any suggestions.

      Comment

      Working...
      X