-->
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: Entity not updated in session but up to date in DB
PostPosted: Wed Dec 12, 2012 12:08 pm 
Newbie

Joined: Wed Dec 12, 2012 11:52 am
Posts: 1
Hi,

I'm new to this forum, so hello everyone.

I've come across a strange issue which I have solved in a way that does not entirely satisfy me. Let me explain.

I have a table in DB, let's say Account(id, customer, money). And I have a view of this table, AccountView(id, customer, money), which lists all account with money < 0.

In my Java code, I have 2 entities, AccountEntity and AccountViewEntity.

At some point, I have a hibernate session that is opened. Then I do some processing, which repeats several times the same operations:
1. reading AccountEntity with id=A
2. updating AccountEntity with id=A
3. loading a list of AccountViewEntity including the one with id=A (and possibly others)

The first time everything is ok, since this is the first time in session that we read/write each Entity.

But in the second pass, I have the correct value for AccountEntity, but AccountViewEntity is wrong. It actually does not take into account the modification made in step 2. In the database, I can see that everything is fine, but in the application, the old value still stands.

I have come to suspect this is because the AccountViewEntity object did not change in the session, thus hibernate won't require it to be loaded from the DB again. So my solution was to add a getSession().refresh(AccountViewEntity) each time.

Does anyone have a better idea on how solve this in a more convenient way? Is there a configuration for hibernate that will not require this call?

Thanks in advance.


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.