Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Hibernate objects need values from db trigger while not yet

Thread view: 
cmi@ch.ibm.com - 23 Nov 2005 19:15 GMT
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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.