使用JPA的Hibernate Cache不起作用

时间:2017-01-23 09:46:37

标签: hibernate jpa hibernate-cache

我使用实体管理器Hibernate的第二级缓存。对于投资小的对象 - 好的。 但是如果对象有其他对象的大附件,则日志查询Hibernate主要的精华重复了几次:

    ....from
2017-01-23 12:04:20,528 INFO  [stdout] (default task-38)         doc_contract contract0_ 
2017-01-23 12:04:20,529 INFO  [stdout] (default task-38)     inner join
2017-01-23 12:04:20,529 INFO  [stdout] (default task-38)         doc_abstract_document contract0_1_ 
2017-01-23 12:04:20,529 INFO  [stdout] (default task-38)             on contract0_.entry_id=contract0_1_.entry_id 
2017-01-23 12:04:20,529 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,543 INFO  [stdout] (default task-38)         dict_organization organizati1_ 
2017-01-23 12:04:20,543 INFO  [stdout] (default task-38)             on contract0_.org_entry_id=organizati1_.entry_id 
2017-01-23 12:04:20,543 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,543 INFO  [stdout] (default task-38)         dict_organization organizati2_ 
2017-01-23 12:04:20,544 INFO  [stdout] (default task-38)             on organizati1_.parent_id=organizati2_.entry_id 
2017-01-23 12:04:20,544 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,544 INFO  [stdout] (default task-38)         dict_contractor_account contractor3_ 
2017-01-23 12:04:20,544 INFO  [stdout] (default task-38)             on contract0_.account_entry_id=contractor3_.entry_id 
2017-01-23 12:04:20,545 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,545 INFO  [stdout] (default task-38)         dict_bank bank4_ 
2017-01-23 12:04:20,545 INFO  [stdout] (default task-38)             on contractor3_.bank_entry_id=bank4_.entry_id 
2017-01-23 12:04:20,545 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,545 INFO  [stdout] (default task-38)         dict_contractor contractor5_ 
2017-01-23 12:04:20,546 INFO  [stdout] (default task-38)             on contractor3_.contractor_entry_id=contractor5_.entry_id 
2017-01-23 12:04:20,546 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,551 INFO  [stdout] (default task-38)         dict_contractor contractor6_ 
2017-01-23 12:04:20,567 INFO  [stdout] (default task-38)             on contract0_.contractor_entry_id=contractor6_.entry_id 
2017-01-23 12:04:20,567 INFO  [stdout] (default task-38)     where
2017-01-23 12:04:20,567 INFO  [stdout] (default task-38)         contract0_.entry_id=?

.... from
2017-01-23 12:04:20,772 INFO  [stdout] (default task-38)         doc_contract contract0_ 
2017-01-23 12:04:20,772 INFO  [stdout] (default task-38)     inner join
2017-01-23 12:04:20,773 INFO  [stdout] (default task-38)         doc_abstract_document contract0_1_ 
2017-01-23 12:04:20,773 INFO  [stdout] (default task-38)             on contract0_.entry_id=contract0_1_.entry_id 
2017-01-23 12:04:20,773 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,773 INFO  [stdout] (default task-38)         dict_organization organizati1_ 
2017-01-23 12:04:20,773 INFO  [stdout] (default task-38)             on contract0_.org_entry_id=organizati1_.entry_id 
2017-01-23 12:04:20,774 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,774 INFO  [stdout] (default task-38)         dict_organization organizati2_ 
2017-01-23 12:04:20,774 INFO  [stdout] (default task-38)             on organizati1_.parent_id=organizati2_.entry_id 
2017-01-23 12:04:20,774 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,774 INFO  [stdout] (default task-38)         dict_contractor_account contractor3_ 
2017-01-23 12:04:20,780 INFO  [stdout] (default task-38)             on contract0_.account_entry_id=contractor3_.entry_id 
2017-01-23 12:04:20,780 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,780 INFO  [stdout] (default task-38)         dict_bank bank4_ 
2017-01-23 12:04:20,780 INFO  [stdout] (default task-38)             on contractor3_.bank_entry_id=bank4_.entry_id 
2017-01-23 12:04:20,781 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,781 INFO  [stdout] (default task-38)         dict_contractor contractor5_ 
2017-01-23 12:04:20,781 INFO  [stdout] (default task-38)             on contractor3_.contractor_entry_id=contractor5_.entry_id 
2017-01-23 12:04:20,781 INFO  [stdout] (default task-38)     left outer join
2017-01-23 12:04:20,788 INFO  [stdout] (default task-38)         dict_contractor contractor6_ 
2017-01-23 12:04:20,788 INFO  [stdout] (default task-38)             on contract0_.contractor_entry_id=contractor6_.entry_id 
2017-01-23 12:04:20,789 INFO  [stdout] (default task-38)     where
2017-01-23 12:04:20,789 INFO  [stdout] (default task-38)         contract0_.entry_id=?

主要实体:

    @Entity
@Table(name = "doc_contract")
@Cacheable(true)
@SequenceGenerator(name = "CUST_SEQ", sequenceName = "DOC_SEQ", allocationSize = 1)
public class Contract extends AbstractSignedDocument implements Cloneable {

persistence.xml文件:

    <properties>
         <!-- Properties for Hibernate -->
         <property name="hibernate.hbm2ddl.auto" value="validate" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect" />

         <!--Кеш второго уровня-->
          <property name="hibernate.cache.region.factory_class" value="org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory"/>
          <property name="hibernate.cache.infisnisspan.cachemanager" value="java:jboss/infinispan/container/hibernate"/>
          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
          <property name="hibernate.cache.use_second_level_cache" value="true"/>
          <property name="hibernate.cache.use_query_cache" value="true"/>

          <property name="hibernate.ejb.interceptor.session_scoped" value="ru.fsgp.pfhdn.service.DBInterceptor"/>

          <property name="hibernate.generate_statistics" value="true"/>
          <property name="hibernate.cache.use_structured_entries" value="true"/>

      </properties>

任何人都可以建议为什么会这样吗?感谢

1 个答案:

答案 0 :(得分:0)

它有所帮助 <shared-cache-mode>ALL</shared-cache-mode> 我的回答正文代码