I use Hibernate and MySQL and I need to store the articles in database. The article entity has a field:
@Lob
@Basic(fetch=EAGER)
@Column(name="CONTENT")
private byte[] content;
Is this entity cacheable in Hibernate?
I use Hibernate and MySQL and I need to store the articles in database. The article entity has a field:
@Lob
@Basic(fetch=EAGER)
@Column(name="CONTENT")
private byte[] content;
Is this entity cacheable in Hibernate?
You can cache your entity using the @Cacheable
annotation, you're supposed to specify a <shared-cache-mode>
in the persistence.xml
(or the equivalent javax.persistence.sharedCache.mode when creating the EntityManagerFactory).
Below, a sample persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
<persistence-unit name="ProjectPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
...
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>