Announcement Announcement Module
No announcement yet.
hibernate + version & txn mgmt =no StaleObjectStateExcep Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:
    DEBUG persister.entity.BasicEntityPersister - org.sample.domain.User.version is dirty
    Where version is the version column.


  • #2
    Spring bean follows...
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//">
            <!-- WebLogic transaction manager -->
            <bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
            <bean id="adminManagerTransactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
                    <property name="properties">
                                    <prop key="lookupUser">
                                    <prop key="updateUser">                        
            <!-- 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 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 id="adminManagerThrottleAdvice" class="com.sample.frameworks.throttle.ThrottleInterceptorImpl">
                    <property name="throttler"><ref bean="inflightCounter"/></property>
                    <property name="counter"><ref bean="adminManagerCounter"/></property>
            <bean id="adminManagerThrottleAdvisor" class="">
                    <property name="mappedNames"><list><value>registerContact</value><value>updateContact</value></list></property>
                    <property name="advice"><ref bean="adminManagerThrottleAdvice"/></property>
            <!-- 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>
                                                    <property name="auditor"><ref bean="hibernateAuditDao"/></property>


    • #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.