Announcement Announcement Module
Collapse
No announcement yet.
Hibernate save object queries don't work inside step context transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate save object queries don't work inside step context transaction

    Hello, my problem seems simple :

    Inside my HibernateAwareWriter write method, I do :

    hibernateTemplate.save(myobject);
    hibernateTemplate.flush();

    But no SQL query logged by hibernate whereas log4j properly configured (as it does log for simple select queries)

    ...

    conf :

    hibernate.db.dialect=org.hibernate.dialect.Oracle1 0gDialect
    hibernate.show_sql=true
    hibernate.use.query.cache=false
    hibernate.jdbc.batch_size=20
    hibernate.cache.use_second_level_cache=false


    I just want want my update query to be fired...help

  • #2
    Are you sure your ItemWriter.write() method is being called at all? If you flush inside the write method there should be an insert emitted immediately. Unless, I suppose, the object you are trying to save is already persistent. Where did you get the object from that you are saving?

    Comment


    • #3
      Well, I'm sure write method is called thanks to logs and... my object has just been instanciated like a POJO which is mapped by hibernate.

      some people told me my problem is with the transactionManager that is not properly configured. Well that's right I'm using two dataSources, one for spring batch logging tables, and another for business data...But I keep thinking there is something else.

      Comment


      • #4
        Originally posted by tstebut View Post
        some people told me my problem is with the transactionManager that is not properly configured. Well that's right I'm using two dataSources, one for spring batch logging tables, and another for business data...
        That's probably the issue then. Your Hibernate session is not tied to a transaction (or at least not to the right transaction). I'm not sure that explains why the flush doesn't result in an insert being emitted, but I am sure that you need to make sure there is only one transaction manager. To be safe it should be using JTA, otherwise you could try using TransactionAwareDataSource for your business transaction - but then you need to try and detect duplicate items in case there is a failure between the commit of the batch meta data and the commit of the business data.

        Even easier (and therefore highly recommended) is just to only use one data source.

        Comment


        • #5
          Thanks for the advices...

          I think I'll get it work.
          Last edited by tstebut; Apr 28th, 2008, 05:31 AM.

          Comment

          Working...
          X