Hibernate Cache с JPA не работает

Я использую кеш второго уровня с менеджером сущностей 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 ответ

Это помогло<shared-cache-mode>ALL</shared-cache-mode> Код моего ответа

Другие вопросы по тегам