[Opensymphony-oscache] Bug in OSCache + Hibernate Query Cache?

Handerson Ferreira Gomes <[email protected]> Mon, 25 Jul 2005 10:30:53 CDT
Newsgroups gmane.comp.java.open-symphony.os-cache
Message-ID <13698276.1122305496864.JavaMail.os-j2ee@opensymphony01.contegix.com>
I'm sorry if this list isn't the correct place to discuss this issue.

I'm caching a Hibernate Query using OSCache and the behavior isn't
what I was expecting.
Seems that the cache ignores the query parameters to construct the
cache key, therefore, doesn't matter what parameters values I set in
the query, the results is always the result of the first executed
query.

Please, look the example below:

[b]public Customer getCustomer(String firstName, String lastName) {
 Query q = session.createQuery("from customer c where c.firstName =
:firstName and c.lastName=:lastName");
 q.setString("firstName",firstName);
 q.setString("lastName",lastName);
 q.setCacheable(true);
 return (Customer) q.uniqueResult();
}[/b]

Then I do:
[b]
Customer cust1 = getCustomer("John","Dude");
Customer cust2 = getCustomer("Paul","Buddy");
[/b]
In this example, cust2 is John Dude, since the cache contains the
resultset for this query.

I tried other cache implementations for Hibernate and it works as I
expected, the cache key uses the parameter values from the query.

Using a query like
[b]
"from customer c where c.firstName = '"+ firstName + "' and
c.lastName='"+ lastName+"'"; [/b]
fix the problem, but I would like to use named parameters.

Why I don't use another cache implementation?
I think OSCache is great project and the JGroups functionality is unique on OSCache and essential for us.

Thanks in advance.
Handerson Gomes
Summa Technologies
http://www.summa-tech.com

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=4670&messageID=11335#11335