Results 1 to 8 of 8

Thread: Hibernate objects need values from db trigger while not yet commited

  1. #1
    Join Date
    Mar 2005
    Location
    Switzerland
    Posts
    12

    Post 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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?

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Mar 2005
    Location
    Switzerland
    Posts
    12

    Default 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.

  6. #6
    Join Date
    Jan 2005
    Location
    Sofia, Bulgaria
    Posts
    38

    Default

    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.
    Rostislav Georgiev

  7. #7
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    38

    Default

    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

  8. #8
    Join Date
    Nov 2005
    Posts
    3

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •