-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Cascaded refresh doesn't load records inserted into database
PostPosted: Thu Jul 24, 2008 5:00 pm 
Newbie

Joined: Thu Jul 24, 2008 4:15 pm
Posts: 2
I've got one-to-many relation between class A (Parent/one) and B (child/many) in a way that A contains a list of B's.

I've got the following situation: I know that since I have loaded A and cascaded list of Bs, there was a new B record added having A as parent.

So I use em.refresh(a) to refresh the a instance (of class A). The instance is configured to cascade the refresh on the collection of Bs. When I turn show_sql to true I the following during the refresh:

SELECT B .... WHERE ID=?
SELECT B ... WHERE ID=?
SELECT A .... WHERE ID=?

In the above case the list of B has exactly two elements. So it appears that hiberante reloads the two B records from the database and then it rereads A record.

But what if there was a new B record related to A inserted? In such case the refresh won't extend the collection with the inserted records. It would just read the records it knew about when it loaded the A object.

How do I force hibernate to reread the A/B so it recognizes the inserted data, not just the data that is updated in the database?

Should I consider it a bug? It appears that it doesn't make full refresh - it refreshes the content of the records read previously, but it doesn't refresh relations between records. For me it's quite unexpected behaviour.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 4:15 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If someone is inserting data into the database, you can just have Hibernate refresh its data. But it's not a bug if someone goes in and adds something to the database without Hibernate knowing about it.

Locks on the database might help alleviate this problem.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 4:42 am 
Newbie

Joined: Thu Jul 24, 2008 4:15 pm
Posts: 2
Let me rephrase the problem - it's not that someone adds record. The problem is that hibernate doesn't read added records during refreshing it's data.

For example - I have an order that I inserted into the database. But due to some business logic triggers the database extends the item list in the database and adds transport cost to the order. I am aware of that logic and I refresh my order to make sure that I synchronized it with the database. Those items that were updated by the trigger refresh fine. However any item that was inserted by the trigger is not visible.

It's not what I would expect from cascaded refresh. I would rather expect that hibernate reads not only updated records, but also all the related inserted records. However looking at the SQL statements generated hibernate cannot deduce related child records added to parent.

Cameron McKenzie wrote:
If someone is inserting data into the database, you can just have Hibernate refresh its data.


The point here is that Hibernate won't refresh the inserted data. It only refreshes updated data, it probably noticed deleted data, but it's simply impossible to grab inserted data with such sql statements. So I can't just have Hibernate refresh its data.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.