Announcement Announcement Module
Collapse
No announcement yet.
HibernateAwarItemWriter commit=1 after failure Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateAwarItemWriter commit=1 after failure

    Hi,

    I have problem with HibernateAwareItemWriter (1.1.3-A). When hibernate batch fails (on flush) then it restart batch from last known position but according to log file it does not commit after each item processed. I though that it was problem with item object identity (I created itemKeyGenerator which returned hibernate entity id value as it's identifier).

    here is listing when flush fails

    Code:
    07 Jan 2009 21:34:30,196 DEBUG [main] (HibernateTemplate.java:435) - Not closing pre-bound Hibernate Session after HibernateTemplate
    07 Jan 2009 21:34:30,196 DEBUG [main] (RepeatTemplate.java:208) - Repeat operation about to start at count=999
    07 Jan 2009 21:34:30,196 DEBUG [main] (RetryTemplate.java:164) - Retry: count=0
    07 Jan 2009 21:34:30,197 DEBUG [main] (GenericSaveOrUpdateHibernateItemWriter.java:24) - id = 12KY-ZW4Y4S
    07 Jan 2009 21:34:30,197 DEBUG [main] (HibernateTemplate.java:410) - Found thread-bound Session for HibernateTemplate
    07 Jan 2009 21:34:30,198 DEBUG [main] (HibernateTemplate.java:435) - Not closing pre-bound Hibernate Session after HibernateTemplate
    07 Jan 2009 21:34:30,198 DEBUG [main] (RepeatTemplate.java:415) - Repeat is complete according to policy and result value.
    07 Jan 2009 21:34:30,198 DEBUG [main] (HibernateTemplate.java:410) - Found thread-bound Session for HibernateTemplate
    07 Jan 2009 21:34:30,503  WARN [main] (JDBCExceptionReporter.java:77) - SQL Error: -302, SQLState: 22001
    07 Jan 2009 21:34:30,503 ERROR [main] (JDBCExceptionReporter.java:78) - DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null, DRIVE
    R=4.2.73
    07 Jan 2009 21:34:30,504 ERROR [main] (AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
    then it rollback transaction

    Code:
    07 Jan 2009 21:34:30,506 DEBUG [main] (AbstractPlatformTransactionManager.java:821) - Initiating transaction rollback
    07 Jan 2009 21:34:30,506 DEBUG [main] (HibernateTransactionManager.java:670) - Rolling back Hibernate transaction on Session [org.hiberna
    te.impl.SessionImpl@18b70fb]
    07 Jan 2009 21:34:30,518 DEBUG [main] (HibernateTransactionManager.java:730) - Closing Hibernate Session [org.hibernate.impl.SessionImpl@
    18b70fb] after transaction
    07 Jan 2009 21:34:30,518 DEBUG [main] (SessionFactoryUtils.java:789) - Closing Hibernate Session
    07 Jan 2009 21:34:30,519 DEBUG [main] (SimpleRetryExceptionHandler.java:72) - handled non-fatal exception
    and continues like nothing happened, no commit after each item

    Code:
    07 Jan 2009 21:34:30,520 DEBUG [main] (AbstractPlatformTransactionManager.java:371) - Creating new transaction with name [null]: PROPAGAT
    ION_REQUIRED,ISOLATION_DEFAULT
    07 Jan 2009 21:34:30,520 DEBUG [main] (HibernateTransactionManager.java:496) - Opened new Session [org.hibernate.impl.SessionImpl@80f252]
     for Hibernate transaction
    07 Jan 2009 21:34:30,520 DEBUG [main] (HibernateTransactionManager.java:507) - Preparing JDBC Connection of Hibernate Session [org.hibern
    ate.impl.SessionImpl@80f252]
    07 Jan 2009 21:34:30,520 DEBUG [main] (HibernateTransactionManager.java:572) - Exposing Hibernate transaction as JDBC transaction [jdbc:d
    b2://some.host.com:50000/siadm, UserName=siadm, IBM Data Server Driver for JDBC and SQLJ]
    07 Jan 2009 21:34:30,521 DEBUG [main] (RepeatTemplate.java:442) - Starting repeat context.
    07 Jan 2009 21:34:30,521 DEBUG [main] (RepeatTemplate.java:208) - Repeat operation about to start at count=0
    07 Jan 2009 21:34:30,521 DEBUG [main] (RetryTemplate.java:164) - Retry: count=0
    07 Jan 2009 21:34:30,522 DEBUG [main] (GenericSaveOrUpdateHibernateItemWriter.java:24) - id = 12KY-ZNC364
    07 Jan 2009 21:34:30,522 DEBUG [main] (HibernateTemplate.java:410) - Found thread-bound Session for HibernateTemplate
    07 Jan 2009 21:34:30,523 DEBUG [main] (HibernateTemplate.java:435) - Not closing pre-bound Hibernate Session after HibernateTemplate
    07 Jan 2009 21:34:30,523 DEBUG [main] (RepeatTemplate.java:208) - Repeat operation about to start at count=1
    07 Jan 2009 21:34:30,524 DEBUG [main] (RetryTemplate.java:164) - Retry: count=0
    07 Jan 2009 21:34:30,524 DEBUG [main] (GenericSaveOrUpdateHibernateItemWriter.java:24) - id = 12KY-ZM1ZM6
    07 Jan 2009 21:34:30,524 DEBUG [main] (HibernateTemplate.java:410) - Found thread-bound Session for HibernateTemplate
    07 Jan 2009 21:34:30,525 DEBUG [main] (HibernateTemplate.java:435) - Not closing pre-bound Hibernate Session after HibernateTemplate
    07 Jan 2009 21:34:30,526 DEBUG [main] (RepeatTemplate.java:208) - Repeat operation about to start at count=2
    07 Jan 2009 21:34:30,526 DEBUG [main] (RetryTemplate.java:164) - Retry: count=0
    07 Jan 2009 21:34:30,526 DEBUG [main] (GenericSaveOrUpdateHibernateItemWriter.java:24) - id = 12KY-ZBK23T

    Let me know if you need more detailed information, I'm lost I do not know where the problem could be. Thanks for your help.

  • #2
    Are you sure you configured the HibernateAwareItemWriter correctly? If so you are probably right to suspect a problem with object identity. Can you post your implementation of equals() and hashCode() for the items?

    Comment


    • #3
      Dave,

      is not ItemKeyGenerator enough to identify item? I have implementation which returns value of primary key of the entity.

      here is my step configuration:

      Code:
      <bean parent="skipLimitStep" id="lnToDb2Step" class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean">
      	<property name="skipLimit" value="10"></property>
      	<property name="itemReader" ref="lnFormItemReader"></property>
      	<property name="itemWriter" ref="lnToDb2ItemTransformerWriter"></property>
      	<property name="commitInterval" value="1000"></property>
      	<property name="itemKeyGenerator" ref="entityKeyGenerator"></property>
      </bean>

      I inherits hash and equals methods from java.lang.Object and I have item processor which creates new instance each time.

      here is my hibernate configuration with HibernateAwareItemWriter:

      Code:
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      	<property name="configLocation" value="${hibernate.cfg}"></property>
      	<property name="dataSource" ref="siadmDataSource"></property>
      	<property name="configurationClass"><value>org.hibernate.cfg.AnnotationConfiguration</value></property>
      	<property name="hibernateProperties">
                  <props>
                      <prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
                  </props>
              </property>
      </bean>
      
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
      	<property name="sessionFactory" ref="sessionFactory"></property>
      </bean>
      
      <bean id="insertOnlyHibernateItemWriter" class="com.ibm.sk.spring.batch.commons.hibernate.GenericInsertOnlyHibernateItemWriter">
      	<property name="sessionFactory" ref="sessionFactory"></property>
      </bean>
      
      <bean id="insertOnlyItemWriter" class="org.springframework.batch.item.database.HibernateAwareItemWriter">
      	<property name="sessionFactory" ref="sessionFactory"></property>
      	<property name="delegate" ref="insertOnlyHibernateItemWriter"></property>
      </bean>
      
      
      <bean id="saveOrUpdateHibernateItemWriter" class="com.ibm.sk.spring.batch.commons.hibernate.GenericSaveOrUpdateHibernateItemWriter">
      	<property name="sessionFactory" ref="sessionFactory"></property>
      </bean>
      
      <bean id="saveOrUpdateItemWriter" class="org.springframework.batch.item.database.HibernateAwareItemWriter">
      	<property name="sessionFactory" ref="sessionFactory"></property>
      	<property name="delegate" ref="saveOrUpdateHibernateItemWriter"></property>
      </bean>
      I tried to run spring-batch samples and I see that when item fails there it commints after each item, while in my case it is not.

      Comment


      • #4
        problem was with object identity, I implemented proper hashCode and equals functions and now it works, thank for the hint.

        Comment

        Working...
        X