-->
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.  [ 1 post ] 
Author Message
 Post subject: Getting partial stale data using Hibernate
PostPosted: Thu Jun 24, 2010 10:38 am 
Newbie

Joined: Thu Jun 24, 2010 9:50 am
Posts: 1
Hi all,

I have this interesting, yet frustrating case where Hibernate is getting partial stale data.

So I've configured my Hibernate configurations to manipulate 3 classes: A, B, and C. Class A contains/references B, and B contains a set of C, so something like

A -> B -> C1
-> C2
....

A, B and C are mapped to different tables, and here is a part of B's hibernate mapping configuration that describes its relationship with C:
<set name="C_refs" inverse="true" lazy="true" table="C" fetch="select">
<key>
<column name="C_id" not-null="true" />
</key>
<one-to-many class="C" />
</set>
Of course, A and B have other attributes and may refer to other classes, which are mapped to other tables.

The behavior I notice is that, whenever I create an instance of A (and I added in new Cs for A), the save/update through Session.persist(A)/Session.update(A) correctly saves A, B and Cs. So, I do something like:
Session session = sessionFactory.openSession();
Transaction transac = session.beginTransaction();
A a = new A();
B b = new B();
C c = new C();

a.setData("A");
a.setB(b);
b.setData("B");
b.addC(c);
c.setData("C");

session.persist(a);
transac.commit();

print(a.getData()); // Print right value
print(a.getB().getData()); // print right value
print (a.getB().getC().getData()); // print stale value!!

session.close();

However, if I try to get data from the object in memory afterwards, I'm getting stale data for ONLY C. Other attributes of A or B are the updated/persisted new values, except for contents of C.
I tried a couple of things:
- Commit the session's transaction after persist/update: still getting stale data only for C
- Change the flush mode to ALWAYS or COMMIT: still the same thing
- Close the session after commit, then open a new session, then perform a query to get A again: only this can help me get the new contents of C

So, I'm very confused at what is causing the behavior. Why am I seeing stale data even after a flush and commit? If I set A.setAttrib("x"), then shouldn't A.getAttrib() return "x"?? (no matter whether the data is updated to db or not, since the updated value is in memory?)


Thanks,
mckwil


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

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.