2017-01-23 36 views
0

我將第二級緩存與實體管理器Hibernate一起使用。對於有小投資的對象 - 好的。 但如果對象具有其他對象的大附件,記錄查詢,Hibernate的主要精髓重複多次:使用JPA的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> 

任何人都可以提出爲什麼這可能是?由於

+0

我們看不到你用來生成日誌,或IDS被綁定到查詢的代碼。它看起來像它被配置爲使用Infinispan,是否有一些管理工具,它允許你看到它當前在緩存中。 –

回答

0

它幫助 <shared-cache-mode>ALL</shared-cache-mode> 我的回答機身碼

+0

它在所有實體中啓用緩存。我返回了ENABLE_SELECTIVE。 幫助需要 – user3602070