Hello,
I have a simple problem :
given a set of identifiers [1,3,98,...], I want to write a function that returns the list of objects that exist with those identifiers in the database. I want also use the second level cache, to only query the db for the non-cached identifiers.
For example if i have the set [1,3,8,43,54]. If i know that 1 and 3 are in second level cache, i use the cache and only query the db for the rest :
select * from object where id in (8,43,54)
For that to work i must know if a particular identifier is present in the second level cache.
I cannot make something like :
Session.load(1)
Session.load(3)
Session.load(8)
Session.load(43)
Session.load(54)
because I am not sure that the identifiers exist in the DB.
And I cannot make
Session.get(1)
Session.get(3)
Session.get(8)
Session.get(43)
Session.get(54)
Because then it will make a query for each non-cached object, which is not efficient.
And i can't make
select * from object where id in (1,3,8,43,54)
because I am not using the second level cache then.
So my conclusion is that I must know if a particular identifier is present in the second level cache. Is there a way to know that?
Thx a lot for your help
Antoine
|