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.
|