Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide transactional support for Infinispan 2nd level cache [SPR-9087] #13725

Closed
spring-issuemaster opened this issue Feb 2, 2012 · 7 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Feb 2, 2012

Jan Goyvaerts opened SPR-9087 and commented

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.

However, there is no way yet to integrate the Spring transaction manager for Infinispan. (At least, I didn't found a way.)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="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">

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

  <!-- configuration transactions are done with @Transactional -->
  <tx:annotation-driven transaction-manager="transactionManager"/>

  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
  </bean>

  <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
  </bean>

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

  <!-- Describes how to create hibernate sessions -->
  <!-- "persistenceUnitName" points to META-INF/persistence.xml -->
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
    <property name="persistenceUnitName" value="foo"/>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaProperties">
      <props>
        <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.InfinispanRegionFactory</prop>
        <prop key="hibernate.cache.use_second_level_cache">true</prop>
        <prop key="hibernate.cache.use_query_cache">true</prop>
        <prop key="hibernate.cache.infinispan.statistics">true</prop>
        <prop key="hibernate.transaction.manager_lookup_class">... something of Spring should be here ... </prop>
        <prop key="hibernate.hbm2ddl.auto">create</prop>
        <prop key="hibernate.jdbc.batch_size">1000</prop>
        <prop key="hibernate.show_sql">false</prop>
        <prop key="hibernate.dialect">${database.hibernate.dialect}</prop>
      </props>
    </property>
  </bean>
</beans>

Issue Links:

  • #15217 Add Infinispan Cache Implementation ("duplicates")

1 votes, 4 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 4, 2012

Chris Beams commented

Costin, could you comment here?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 7, 2012

Juergen Hoeller commented

As far as I know, such 2nd level cache integration only works through JTA. I'm afraid Spring won't be able to do much on its own here unless you configure it with JtaTransactionManager and a corresponding "hibernate.transaction.manager_lookup_class" for the specific JTA provider of your choice...

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 7, 2012

Jan Goyvaerts commented

I'm sorry if I ask dumb questions, but I'm a bit foreign to Spring's solution with transaction management. :-)

Does this mean I can't use the JPA version then ?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 23, 2012

Jan Goyvaerts commented

Hello ?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 5, 2014

Stéphane Nicoll commented

See #15217

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 5, 2014

Stevo Slavić commented

This issue is resolved as Duplicate of #15217, while issue link is in opposite direction.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 5, 2014

Stéphane Nicoll commented

fixed, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.