Hibernate version: 3.1.2
Does the L2 cache hold the values of extended properties that are not mapped to the database by hibernate?
For example, this POJO:
Code:
public class Account implements java.io.Serializable {
//Mapped to database via hibernate
private int accountid;
private int name;
//Not mapped to database... just properties
private boolean flag;
private int expensiveToCalculate;
//Method called by event listener
public void load(){
if (!flag){
//Set the flag to true so expensive work only done once
flag=true;
//Calculate stuff
expensiveToCalculate = someOtherExpensiveMethod();
}
}
}
The load() method is called from a PostLoadEventListener. It works properly the first time the object is loaded... the expensive calculation is done and the flag is set so that I can use the object from the cache without doing the expensive calculation again.
However, the next time I access the Account object it calls load(), which is fine, but it does the expensive calculation a second time... because the value of boolean flag is apparently not held in cache... or is re-initialized to its default value each time the Account object is pulled from the cache. Is this correct?
I know that hibernate is pulling the object from cache because I'm outputting sql and am not seeing any additional sql calls. I have the object cached and the query cached.
It appears that the L2 cache only caches values that are mapped by hibernate, not other properties that I add to the POJO and not the mapping.
Thanks for any insight.
Joe