Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Last active June 9, 2016 04:06
Show Gist options
  • Save thjanssen/d00e6ecd621f2dd75648ae550505fa9b to your computer and use it in GitHub Desktop.
Save thjanssen/d00e6ecd621f2dd75648ae550505fa9b to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="my-persistence-unit">
...
<properties>
...
<!-- configure caching -->
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
</properties>
</persistence-unit>
</persistence>
Session s = (Session) em.getDelegate();
Query q = s.createQuery("SELECT a FROM Author a WHERE id = :id");
q.setParameter("id", 1L);
q.setCacheable(true);
log.info(q.uniqueResult());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment