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
Jimi Hullegård - 24 Nov 2005 00:31 GMT
> Dear all,
>
[quoted text clipped - 3 lines]
> 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
cmi@ch.ibm.com - 25 Nov 2005 13:01 GMT
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.
iksrazal@gmail.com - 25 Nov 2005 13:18 GMT
> Dear all,
>
[quoted text clipped - 25 lines]
> 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/