<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jan_goyvaerts" rel="nofollow">Jan Goyvaerts</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9087?redirect=false" rel="nofollow">SPR-9087</a></strong> and commented</p>
<p dir="auto">I have a classic JPA configuration in which I'm using Hibernate. I'd like to switch to Infinispan for 2nd level- and query caching. Mainly because this cache takes the transaction into account. This is for a standalone deployment on Tomcat.</p>
<p dir="auto">However, there is no way yet to integrate the Spring transaction manager for Infinispan. (At least, I didn't found a way.)</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
       xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
       xmlns:task=&quot;http://www.springframework.org/schema/task&quot;
       xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd&quot;&gt;

  &lt;!-- Scan our code for Spring annotations @Component, @Repository and @Service annotated classes are added --&gt;
  &lt;!-- to the Spring configuration as if they're declared in this file. --&gt;
  &lt;context:component-scan base-package=&quot;com.foo&quot; scoped-proxy=&quot;targetClass&quot;/&gt;

  &lt;!-- configuration transactions are done with @Transactional --&gt;
  &lt;tx:annotation-driven transaction-manager=&quot;transactionManager&quot;/&gt;

  &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;
    &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;entityManagerFactory&quot;/&gt;
  &lt;/bean&gt;

  &lt;bean id=&quot;jpaTemplate&quot; class=&quot;org.springframework.orm.jpa.JpaTemplate&quot;&gt;
    &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;entityManagerFactory&quot;/&gt;
  &lt;/bean&gt;

  &lt;!-- Describes how to connect to the database --&gt;
  &lt;!-- Describes to reuse database connections as making them is expensive --&gt;
  &lt;bean id=&quot;dataSource&quot; class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot; destroy-method=&quot;close&quot;&gt;
    &lt;property name=&quot;user&quot; value=&quot;${database.user.name}&quot;/&gt;
    &lt;property name=&quot;password&quot; value=&quot;${database.user.password}&quot;/&gt;
    &lt;property name=&quot;driverClass&quot; value=&quot;${database.driver}&quot;/&gt;
    &lt;property name=&quot;jdbcUrl&quot; value=&quot;${database.url}&quot;/&gt;
    &lt;property name=&quot;initialPoolSize&quot; value=&quot;1&quot;/&gt;
    &lt;property name=&quot;maxPoolSize&quot; value=&quot;4&quot;/&gt;
    &lt;property name=&quot;minPoolSize&quot; value=&quot;1&quot;/&gt;
    &lt;property name=&quot;acquireIncrement&quot; value=&quot;1&quot;/&gt;
    &lt;property name=&quot;acquireRetryAttempts&quot; value=&quot;0&quot;/&gt;
  &lt;/bean&gt;

  &lt;!-- Describes how to create hibernate sessions --&gt;
  &lt;!-- &quot;persistenceUnitName&quot; points to META-INF/persistence.xml --&gt;
  &lt;bean id=&quot;entityManagerFactory&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;
    &lt;property name=&quot;persistenceProviderClass&quot; value=&quot;org.hibernate.ejb.HibernatePersistence&quot;/&gt;
    &lt;property name=&quot;persistenceUnitName&quot; value=&quot;foo&quot;/&gt;
    &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;/&gt;
    &lt;property name=&quot;jpaProperties&quot;&gt;
      &lt;props&gt;
        &lt;prop key=&quot;hibernate.cache.region.factory_class&quot;&gt;org.hibernate.cache.infinispan.InfinispanRegionFactory&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.cache.use_second_level_cache&quot;&gt;true&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.cache.use_query_cache&quot;&gt;true&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.cache.infinispan.statistics&quot;&gt;true&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.transaction.manager_lookup_class&quot;&gt;... something of Spring should be here ... &lt;/prop&gt;
        &lt;prop key=&quot;hibernate.hbm2ddl.auto&quot;&gt;create&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.jdbc.batch_size&quot;&gt;1000&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.show_sql&quot;&gt;false&lt;/prop&gt;
        &lt;prop key=&quot;hibernate.dialect&quot;&gt;${database.hibernate.dialect}&lt;/prop&gt;
      &lt;/props&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
&lt;/beans&gt;"><pre class="notranslate">&lt;?<span class="pl-ent">xml</span><span class="pl-e"> version</span>=<span class="pl-s"><span class="pl-pds">"</span>1.0<span class="pl-pds">"</span></span><span class="pl-e"> encoding</span>=<span class="pl-s"><span class="pl-pds">"</span>UTF-8<span class="pl-pds">"</span></span>?&gt;
&lt;<span class="pl-ent">beans</span> <span class="pl-e">xmlns</span>=<span class="pl-s"><span class="pl-pds">"</span>http://www.springframework.org/schema/beans<span class="pl-pds">"</span></span>
       <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">xsi</span>=<span class="pl-s"><span class="pl-pds">"</span>http://www.w3.org/2001/XMLSchema-instance<span class="pl-pds">"</span></span>
       <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">context</span>=<span class="pl-s"><span class="pl-pds">"</span>http://www.springframework.org/schema/context<span class="pl-pds">"</span></span>
       <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">tx</span>=<span class="pl-s"><span class="pl-pds">"</span>http://www.springframework.org/schema/tx<span class="pl-pds">"</span></span>
       <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">task</span>=<span class="pl-s"><span class="pl-pds">"</span>http://www.springframework.org/schema/task<span class="pl-pds">"</span></span>
       <span class="pl-e">xsi</span><span class="pl-e">:</span><span class="pl-e">schemaLocation</span>=<span class="pl-s"><span class="pl-pds">"</span>http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</span>
<span class="pl-s">          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd</span>
<span class="pl-s">          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd</span>
<span class="pl-s">          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd<span class="pl-pds">"</span></span>&gt;

  <span class="pl-c"><span class="pl-c">&lt;!--</span> Scan our code for Spring annotations @Component, @Repository and @Service annotated classes are added <span class="pl-c">--&gt;</span></span>
  <span class="pl-c"><span class="pl-c">&lt;!--</span> to the Spring configuration as if they're declared in this file. <span class="pl-c">--&gt;</span></span>
  &lt;<span class="pl-ent">context</span><span class="pl-ent">:</span><span class="pl-ent">component-scan</span> <span class="pl-e">base-package</span>=<span class="pl-s"><span class="pl-pds">"</span>com.foo<span class="pl-pds">"</span></span> <span class="pl-e">scoped-proxy</span>=<span class="pl-s"><span class="pl-pds">"</span>targetClass<span class="pl-pds">"</span></span>/&gt;

  <span class="pl-c"><span class="pl-c">&lt;!--</span> configuration transactions are done with @Transactional <span class="pl-c">--&gt;</span></span>
  &lt;<span class="pl-ent">tx</span><span class="pl-ent">:</span><span class="pl-ent">annotation-driven</span> <span class="pl-e">transaction-manager</span>=<span class="pl-s"><span class="pl-pds">"</span>transactionManager<span class="pl-pds">"</span></span>/&gt;

  &lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>transactionManager<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.orm.jpa.JpaTransactionManager<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>entityManagerFactory<span class="pl-pds">"</span></span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">"</span>entityManagerFactory<span class="pl-pds">"</span></span>/&gt;
  &lt;/<span class="pl-ent">bean</span>&gt;

  &lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>jpaTemplate<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.orm.jpa.JpaTemplate<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>entityManagerFactory<span class="pl-pds">"</span></span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">"</span>entityManagerFactory<span class="pl-pds">"</span></span>/&gt;
  &lt;/<span class="pl-ent">bean</span>&gt;

  <span class="pl-c"><span class="pl-c">&lt;!--</span> Describes how to connect to the database <span class="pl-c">--&gt;</span></span>
  <span class="pl-c"><span class="pl-c">&lt;!--</span> Describes to reuse database connections as making them is expensive <span class="pl-c">--&gt;</span></span>
  &lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>dataSource<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>com.mchange.v2.c3p0.ComboPooledDataSource<span class="pl-pds">"</span></span> <span class="pl-e">destroy-method</span>=<span class="pl-s"><span class="pl-pds">"</span>close<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>user<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>${database.user.name}<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>password<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>${database.user.password}<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>driverClass<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>${database.driver}<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>jdbcUrl<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>${database.url}<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>initialPoolSize<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>maxPoolSize<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>4<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>minPoolSize<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>acquireIncrement<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>acquireRetryAttempts<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>0<span class="pl-pds">"</span></span>/&gt;
  &lt;/<span class="pl-ent">bean</span>&gt;

  <span class="pl-c"><span class="pl-c">&lt;!--</span> Describes how to create hibernate sessions <span class="pl-c">--&gt;</span></span>
  <span class="pl-c"><span class="pl-c">&lt;!--</span> "persistenceUnitName" points to META-INF/persistence.xml <span class="pl-c">--&gt;</span></span>
  &lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>entityManagerFactory<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>persistenceProviderClass<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>org.hibernate.ejb.HibernatePersistence<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>persistenceUnitName<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>foo<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>dataSource<span class="pl-pds">"</span></span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">"</span>dataSource<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>jpaProperties<span class="pl-pds">"</span></span>&gt;
      &lt;<span class="pl-ent">props</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.cache.region.factory_class<span class="pl-pds">"</span></span>&gt;org.hibernate.cache.infinispan.InfinispanRegionFactory&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.cache.use_second_level_cache<span class="pl-pds">"</span></span>&gt;true&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.cache.use_query_cache<span class="pl-pds">"</span></span>&gt;true&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.cache.infinispan.statistics<span class="pl-pds">"</span></span>&gt;true&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.transaction.manager_lookup_class<span class="pl-pds">"</span></span>&gt;... something of Spring should be here ... &lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.hbm2ddl.auto<span class="pl-pds">"</span></span>&gt;create&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.jdbc.batch_size<span class="pl-pds">"</span></span>&gt;1000&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.show_sql<span class="pl-pds">"</span></span>&gt;false&lt;/<span class="pl-ent">prop</span>&gt;
        &lt;<span class="pl-ent">prop</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>hibernate.dialect<span class="pl-pds">"</span></span>&gt;${database.hibernate.dialect}&lt;/<span class="pl-ent">prop</span>&gt;
      &lt;/<span class="pl-ent">props</span>&gt;
    &lt;/<span class="pl-ent">property</span>&gt;
  &lt;/<span class="pl-ent">bean</span>&gt;
&lt;/<span class="pl-ent">beans</span>&gt;</pre></div>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398159189" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/15217" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/15217/hovercard" href="https://github.com/spring-projects/spring-framework/issues/15217">#15217</a> Add Infinispan Cache Implementation (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 4 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=marschall" rel="nofollow">Philippe Marschall</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-10588?redirect=false" rel="nofollow">SPR-10588</a></strong> and commented</p>
<p dir="auto">There currently is an Ehcache implementation of the cache abstraction. It would be interesting for us to have an Infinispan implementation. This would allow us to use <code class="notranslate">ConcurrentMapCache</code> for tests and the built-in JBoss AS 7 cache in production.</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117041" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13725" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13725/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13725">#13725</a> Provide transactional support for Infinispan 2nd level cache (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 7 watchers</p>