Announcement Announcement Module
Collapse
No announcement yet.
Hibernate objects need values from db trigger while not yet commited Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate objects need values from db trigger while not yet commited

    Dear all,

    I have a problem with hibernate objects which are not syncronized with the underlying database record within a running transaction.
    The tricky part is, that certain fields are set in the database using an insert trigger, and I need to get these values into my hibernate business object before it is commited.

    To illustrate, I have the following scenario:

    {tx start by SpringHibernateTransactionManager}

    - crate a new empty OrderBasket business object
    - set some attributes on the OrderBasket
    - call getHibernateTemplate().saveOrUpdate(orderBasket);
    - call getHibernateTemplate().flush();
    - call getHibernateTemplate().findByNamedQuery("OrderBask et.findByUniqueId");
    here we see, that the update date is not set on the business obkect.

    {tx commit by SpringHibernateTransactionManager}

    Even if I call OrderBasket getHibernateTemplate().refresh(orderBasket), it does not help. In this case, I get an exception as follows: "could not load an entity".

    Can anybody give me a hint on where I have to look into?
    Thank you for any help.
    Christoph

  • #2
    The tricky part is, that certain fields are set in the database using an insert trigger, and I need to get these values into my hibernate business object before it is commited.
    I'm not sure if this will help you but the objects will not hit the database unless the transaction is commited, thus the trigger won't happen unless the transaction is commited.

    Comment


    • #3
      As I read the original posting, a flush() is being performed. So the data *should* be inserted into the database (though yet uncommitted)) causing associated triggers to fire.

      Maybe some hibernate caching options prevent the find operation to actually hit the database?

      Regards,
      Andreas

      P.S.: Who rated this yet unconclusive thread with five stars?

      Comment


      • #4
        As I read the original posting, a flush() is being performed. So the data *should* be inserted into the database (though yet uncommitted)) causing associated triggers to fire.
        As you said it should - this is one area where I think every db vendor has it's own semantics. I think it also depends a lot on the settings of the transaction.

        Comment


        • #5
          We are using Oracle 10.1

          Hello everybody
          Thanks for your answers. We are using Oracle 10.1 and I am performing a flush without effect. When I try a refresh, I get the error "could not read an entity", which may be caused by the fact, that the tx was not yet committed, although this does not really make sense to me.

          Comment


          • #6
            Try to call session.clear(); after the getHibernateTemplate().flush();
            And also I think it will be better to have all this calls in one HibernateCallback.doInHibernate(Session session) call.

            Comment


            • #7
              Seems to be a hibernate session cache problem. After flush() the state of the object in memory and in the database are synchronized. If you're accessing the object again, Hibernate will probably use the object from the session cache.
              Try the following:
              #1: Detach the the object from the session and reattach it again.
              or #2: Use a query that doesn't select the object with it's id

              Comment


              • #8
                We are using saveOrUpdate(), flush(), refresh() sequence without problems on Oracle 9.2.

                Comment

                Working...
                X