-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Write transaction sends unnecessary updates
PostPosted: Tue Aug 11, 2009 10:36 pm 
Newbie

Joined: Fri Oct 26, 2007 9:30 am
Posts: 11
Hello,
I migrated my app from Mysql to Oracle. Now I'm facing the problem that every write transaction updates every attribute of every record that was loaded during the transaction even though there weren't any changes. With my MySql configuration that never happened. It was only updating stuff that did actually change.

This creates a problem, because I now often run into unnecessary dead locks, because A objects are updated a lot and B objects rarely.

For example an update to a single object A of table tbl_A will also update all attributes of object B of tbl_B if A has a reference to object B.

The releation between A nd bet would be defined as follows
Code:
@ManyToOne(optional=true)
@JoinColumn(name="b_id", nullable=true)
public B getB() {...}



Here are my EntityManager and my transactionManager definitions, I'm using JPA:
Code:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>                                 
        </property>
        <property name="jpaProperties">
            <util:properties location="classpath:com/obade/codex/dao/jpa/hibernate.properties"/>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>





My tables tbl_A and tbl_B are annotated with
Code:
@Entity
@org.hibernate.annotations.Entity(optimisticLock = OptimisticLockType.VERSION, dynamicUpdate=true)
@org.hibernate.annotations.Cache(usage=org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "xedoc_admin.tbl_A)


I use annotations to control transactional boundaries and the context at the service layer, i.e. my transactional methods in AServiceImpl are annotated with
Code:
   @Transactional(readOnly = false)




I must admit that I am somewhat lost in the documenatation of the transaction configuration.

Thanks for help. Much appreciated.

jacques

Config: Spring 2.5.6, hibernate-core 3.3.2.GA, hibernate-entitymanager 3.4.0.GA, Oracle JDBC Driver version 10.2.0.3.0, Oracle 10.2.0.3 (10GR2)


Top
 Profile  
 
 Post subject: Re: Write transaction sends unnecessary updates
PostPosted: Mon Aug 17, 2009 9:24 pm 
Newbie

Joined: Fri Oct 26, 2007 9:30 am
Posts: 11
I would be really grateful if I could get some help with this issue or at least a pointer - it's a blocking problem and I'm not sure in which direction to move forward.

Would it be advisable to switch to programmatically controled transactions (rather than annotation controlled)?

Is this a known issue? Anyone else ever see this?

Would it be promising to debug into the hibernate implementation to see if can be configured.

Help much appreciated.

THANK YOU!

jacques


Top
 Profile  
 
 Post subject: Re: Write transaction sends unnecessary updates
PostPosted: Sat Aug 22, 2009 4:15 pm 
Newbie

Joined: Fri Oct 26, 2007 9:30 am
Posts: 11
More details, this issue is a blocker for my project, I have to fix it.

If you have information, please share it.

I have written a simple test using programmatic transaction because I was hoping to gain mor control over the behavior when my transaction closes, but the problem reproduces exactly with decalred transactions.

My test creates a read/write context, loads a single object, but doesn't modify it and exits.
Code:
   public Boolean testPersist() {
      // using programmatic transactions
      
      transactionTemplate.execute(
            new TransactionCallback(){
               public Object doInTransaction(TransactionStatus ts) {
                  try{
                     VersionDomain v = versionDao.getVersion(1);
                     
                  }catch (Exception e) {
                     ts.setRollbackOnly();
                  }
                  return ts;
               }
               
            }
            
      );
      return true;
   
   }


My logs show two updates, one for each doamin object loaded: my version, and the product associated with the version in a ManyToOne relation, meaning many versions for each product.

Code:
12:49:46,328 INFO  [STDOUT] 2009-08-22 12:49:46,328 DEBUG [org.hibernate.SQL] - select versiondom0_.id as id41_4_, versiondom0_.codename as codename41_4_, versiondom0_.date_created as date3_41_4_, versiondom0_.date_modified as date4_41_4_, versiondom0_.description as descript5_41_4_, versiondom0_.link as link41_4_, versiondom0_.product_id as product10_41_4_, versiondom0_.unified_version_id as unified7_41_4_, versiondom0_.user_id as user11_41_4_, versiondom0_.versionname as versionn8_41_4_, versiondom0_.nostaw_version as nostaw9_41_4_, product1_.id as id25_0_, product1_.date_created as date2_25_0_, product1_.date_modified as date3_25_0_, product1_.deprecated as deprecated25_0_, product1_.description as descript5_25_0_, product1_.latest_version_id as latest6_25_0_, product1_.link as link25_0_, product1_.name as name25_0_, product1_.restricted as restricted25_0_, product1_.sap_code as sap10_25_0_, product1_.type_id as type14_25_0_, product1_.unified_prod_id as unified11_25_0_, product1_.user_id as user15_25_0_, product1_.nostaw_family as nostaw12_25_0_, product1_.nostaw_product as nostaw13_25_0_, producttyp2_.id as id27_1_, producttyp2_.date_created as date2_27_1_, producttyp2_.date_modified as date3_27_1_, producttyp2_.description as descript4_27_1_, producttyp2_.name as name27_1_, userdomain3_.id as id39_2_, userdomain3_.admin as admin39_2_, userdomain3_.obadenet_uid as obadenet3_39_2_, userdomain3_.date_created as date4_39_2_, userdomain3_.date_modified as date5_39_2_, userdomain3_.kitn_id as kitn6_39_2_, userdomain4_.id as id39_3_, userdomain4_.admin as admin39_3_, userdomain4_.obadenet_uid as obadenet3_39_3_, userdomain4_.date_created as date4_39_3_, userdomain4_.date_modified as date5_39_3_, userdomain4_.kitn_id as kitn6_39_3_ from xedoc_admin.tbl_versions versiondom0_ left outer join xedoc_admin.tbl_products product1_ on versiondom0_.product_id=product1_.id left outer join xedoc_admin.tbl_product_types producttyp2_ on product1_.type_id=producttyp2_.id left outer join xedoc_admin.tbl_users userdomain3_ on product1_.user_id=userdomain3_.id left outer join xedoc_admin.tbl_users userdomain4_ on versiondom0_.user_id=userdomain4_.id where versiondom0_.id=?
12:49:46,586 INFO  [STDOUT] 2009-08-22 12:49:46,586 DEBUG [org.hibernate.SQL] - update xedoc_admin.tbl_products set sap_code=?, nostaw_family=?, nostaw_product=? where id=?
12:49:46,613 INFO  [STDOUT] 2009-08-22 12:49:46,613 DEBUG [org.hibernate.SQL] - update xedoc_admin.tbl_versions set link=?, nostaw_version=? where id=?


What can I do to prevent unecessary updates?

I want to do updates only if the object really was changed. These useless updates are cause deadlocks in the clustered hosting einvirenment.

I was not seeing this behavior while I was using MySql.

Thanks for help.

Looks like bug actually.

Thanks for help. Much appreciated.

jacques

Config: Spring 2.5.6, hibernate-core 3.3.2.GA, hibernate-entitymanager 3.4.0.GA, Oracle JDBC Driver version 10.2.0.3.0, Oracle 10.2.0.3 (10GR2)


Top
 Profile  
 
 Post subject: Re: Write transaction sends unnecessary updates
PostPosted: Sat Aug 22, 2009 5:20 pm 
Newbie

Joined: Fri Oct 26, 2007 9:30 am
Posts: 11
More tangible questions:
-Is it promising to try using another TransactionManager, i.e currently using org.springframework.orm.jpa.JpaTransactionManager.
-Does it need to be fixed in the driver configuration? Currently using
org.hibernate.dialect.Oracle10gDialect
-Can it be fixed by changing the configuration of the transaction manager? usually I get errors when I try to configure transaction properties, i.e.
Quote:
"Spring does not support transaction isolation with JPA"



TIA
jacques


Top
 Profile  
 
 Post subject: Re: Write transaction sends unnecessary updates
PostPosted: Fri Aug 28, 2009 1:39 pm 
Newbie

Joined: Fri Oct 26, 2007 9:30 am
Posts: 11
Found the problem: One of my getters in an object that was almost always loaded was marking the object dirty.

The background is: in oracle empty strings ar stored as NULL. My getter was initializing the null string with an empty string. Whenever this happened in a write context the row was written back to the db on commit.

But the data would not change because the empty string would still be converted to NULl-varchar.

Done.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.