[jboss-user] [JBoss Cache: Core Edition] - Re: Why does em.persist resets the Query cache?
ryanrlamothe
do-not-reply at jboss.com
Sun Feb 8 19:44:32 EST 2009
Well, first of all, query caching is only for named queries.
So, you will need to create an entity which has the following annotation (or XML configuration):
@NamedQueries( { @NamedQuery(name = "Book.findByIdCustom", query = "select b from Book b where b.id < :id") })
Where Book is your entity and id is a field in your entity.
Then you will need to create the following code in your facade:
Query query = entityManager.createNamedQuery("Book.findByIdCustom");
| query.setParameter("id", id);
| query.setHint("org.hibernate.cacheable", true);
| return query.getResultList();
Now, you will need to be careful to evict the query results appropriately to avoid getting stale data in your results.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4208052#4208052
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4208052
More information about the jboss-user
mailing list