Hibernate objects need values from db trigger while not yet

C

cmi

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

{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
 
J

Jimi Hullegård

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.

Can't you just fetch those values by a simple query to the database, and
then manually set them in your bean?

Iterator results = em.createQuery(
"select cat.color, min(cat.birthdate), count(cat) from Cat cat group
by cat.color")
.list()
.iterator();

while ( results.hasNext() )
{
Object[] row = results.next();
Color type = (Color) row[0];
Date oldest = (Date) row[1];
Integer count = (Integer) row[2];
.....
}

http://www.hibernate.org/hib_docs/entitymanager/reference/en/html_single/#d0e556

/Jimi
 
C

cmi

Thank you for your reply. I would like hibernate to handle this
problem, as I should be able to rely on hibernate to synchronize the Bo
and the database record.
 
I

iksrazal

(e-mail address removed) escreveu:
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 object.

{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

This seems like a Spring error on startup, ie, a spelling error or lack
of a declaration. Post your applicationContext.xml and
serviceContext.xml with the transaction. You need to reference your
*hbm* files in your applicationContext.xml.

Another tip - turn on spring and hibernate logging. You should see you
problem entity being loaded.

HTH,
iksrazal
http://www.braziloutsource.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top