0
我使用Hibernate和MySQL,我需要将文章存储在数据库中。文章实体有一个字段:具有@Lob字段的实体是否可在Hibernate中缓存?
@Lob
@Basic(fetch=EAGER)
@Column(name="CONTENT")
private byte[] content;
这个实体可以在Hibernate中缓存吗?
我使用Hibernate和MySQL,我需要将文章存储在数据库中。文章实体有一个字段:具有@Lob字段的实体是否可在Hibernate中缓存?
@Lob
@Basic(fetch=EAGER)
@Column(name="CONTENT")
private byte[] content;
这个实体可以在Hibernate中缓存吗?
您可以使用@Cacheable
注解缓存你的实体,你应该到指定的persistence.xml
一个<shared-cache-mode>
(或创建的EntityManagerFactory当等效javax.persistence.sharedCache.mode)。
下面,样品的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>
但它会为@Lob工作吗? –
是的,因为你会缓存整个实体 –