1 2 Previous Next 15 Replies Latest reply: Sep 25, 2013 4:36 AM by Nibin Jacob Panicker RSS

Working example stand-alone Spring/Hibernate/Infinispan ?

Jan Goyvaerts Newbie

Presumably I'm chasing ghosts here - but for some time already I'm trying to replace EHCache by Infinispan. For the 2nd level- and query caching. And am failing miserably to this day. :-) EHCache fails for an obscure case when being used in VMWare. It seems the right occasion to try another cache library which might not crash and which is even transactional. Especially because it is not that rare to have enterprise applications run in VM's.

 

The bottom line seems (I'm not sure) that Hibernate's transaction factory- and lookup classes can't be used to integrate with Spring's JPATransactionManager. Which means I can't get Infinispan to work.

 

The application is stand-alone, running on Tomcat 7, backed by Spring 3.1 and JPA2. The latter is backed by Hibernate 4.1. All put in a Maven sauce.

 

Does anybody in here had any success yet to use Infinispan in this context ? I'm extending my eternal gratitude to the gentle soul who can help me out. :-)

 

THX !

 

Jan

  • 1. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Galder Zamarreño Master

    Unfortunately we didn't have any users submitting working examples on this combo, but I dont' see why it should not work.

     

    I'd suggest that you post the example that you've build so far, with the tests that you have, and we can work on it?

     

    To be more specific, I'm not sure what type of Spring transaction manager you really need to use here, but what about org.springframework.transaction.jta.JtaTransactionManager ?

     

    According to http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/transaction/jta/JtaTransactionManager.html, this looks to be more suited.

     

    Also, why not use JBoss AS7?

  • 2. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    At least someone who's thinking it's possible ! :-p

     

    I'll work out a simple configuration and post it here.

     

    For the same reason we're not using any other application server: It's a cannon to kill a mosquito. We simply don't need anything more elaborate than Tomcat. Or Jetty for that matter. But as soon as EJB, JMS or something of a higher level is needed I'll be the first to drop whatever we're using. And replace it with a proper application server.

  • 3. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    Okay - here it is: git://javaforge.com/nukeshop

     

    This is how far I get without hacking around. This is meant for a "serious" production environment on which I really can't afford to have invalid cache entries. Or caching not working for that matter.

     

    The solution is most probably the configuration of lines 46 & 47 in WEB-INF/applicationContext.xml. But what should it be ?

     

    Is there a kind soul somewhere who can give me a clue how to link up the transaction manager of Spring with Infinispan ? :-)

     

     

    When trying to deploy the war file you'll get the exception:

     

    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: nukes] Unable to build EntityManagerFactory

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

              at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

              at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)

              at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)

              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)

              at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)

              at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)

              at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)

              at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)

              at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)

              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

              at java.util.concurrent.FutureTask.run(FutureTask.java:166)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

              at java.lang.Thread.run(Thread.java:722)

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: nukes] Unable to build EntityManagerFactory

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

              at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)

              ... 23 more

    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: nukes] Unable to build EntityManagerFactory

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)

              at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)

              at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)

              at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)

              ... 30 more

    Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jta.platform.spi.JtaPlatform]

              at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)

              at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)

              at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)

              at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:96)

              at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2274)

              at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2270)

              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1739)

              at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:93)

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)

              ... 36 more

    Caused by: org.hibernate.service.jta.platform.spi.JtaPlatformException: Unable to build org.hibernate.service.jta.platform.internal.TransactionManagerLookupBridge from specified org.hibernate.transaction.TransactionManagerLookup implementation: org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup

              at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.mapLegacyClasses(JtaPlatformInitiator.java:179)

              at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.getConfiguredPlatform(JtaPlatformInitiator.java:102)

              at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:60)

              at org.hibernate.service.jta.platform.internal.JtaPlatformInitiator.initiateService(JtaPlatformInitiator.java:47)

              at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)

              at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)

              ... 44 more

  • 4. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Steve Ebersole Apprentice

    What are your lines 46 & 47?

  • 5. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    Ow ! Did I forgot to include the Spring context file or was it to check somebody was actually paying attention ? :-p

     

    There they are - put those in bold. The two settings have to set to something working. But what is it ?

     

    <?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"

           xmlns:util="http://www.springframework.org/schema/util"

           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 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

     

     

      <!-- configuration transactions are done with @Transactional -->

      <tx:annotation-driven transaction-manager="transactionManager"/>

     

     

      <!-- JDBC connection pooling -->

      <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

        <property name="user" value="app"/>

        <property name="password" value="app"/>

        <property name="driverClass" value="org.apache.derby.jdbc.EmbeddedDriver"/>

        <property name="jdbcUrl" value="jdbc:derby:./nuke_db;create=true"/>

        <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>

     

      <!-- Use the classic Spring JPA Transaction Manager -->

      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">

        <property name="entityManagerFactory" ref="entityManagerFactory"/>

      </bean>

     

     

      <!-- JPA entity manager; based on embedded Derby. Is shipped with all JVM's. -->

      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

        <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>

        <property name="persistenceUnitName" value="nukes"/>

        <property name="dataSource" ref="dataSource"/>

        <property name="jpaProperties">

          <props>

            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.InfinispanRegionFactory</prop>

           

    <!-- THIS IS THE POINT OF THE EXERCISE -->

           

            <!-- These two settings have to point to the transactionManager bean somehow... -->

    (46)<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>

    (47)<prop key="hibernate.transaction.manager_lookup_class">org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup</prop>

           

    <!-- CAN YOU SPOT THE LOONEY ?-->

           

            <prop key="hibernate.cache.use_second_level_cache">true</prop>

            <prop key="hibernate.cache.use_query_cache">true</prop>

            <prop key="hibernate.generate_statistics">true</prop>

            <prop key="hibernate.hbm2ddl.auto">create</prop>

            <prop key="hibernate.show_sql">true</prop>

            <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>

          </props>

        </property>

      </bean>

    </beans>

  • 6. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Steve Ebersole Apprentice

    Line 47 is waaaaaaay off. 

     

    Line 46 is "ok", depending upon your style of transaction control.  You might need 'org.hibernate.transaction.JTATransactionFactory' or 'org.hibernate.transaction.CMTTransactionFactory'.  But you have not given enough info here to tell.

     

    In lIne 47 you are trying to pass a Infinispan class as a HIbernate contract.  Thats not going to work.  And in 4.x, we (Hibernate) moved away from the generally too-simplistic notion of a "TransactionManager lookup".  Instead, we now have a contract org.hibernate.service.jta.platform.spi.JtaPlatform which describes all aspects of JTA within the given environment.  So the hibernate.transaction.manager_lookup_class is actually deprecated.  If specified, Hibernate will try to map the legacy implementation names to the newer JtaPlatform implementations.  But you specified something completely different here.  So you have 2 options.  The better solution is to use the newer 'hibernate.transaction.jta.platform' setting to name the impl you want to use (org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform here I guess?).  The other possibility is to still use hibernate.transaction.manager_lookup_class as you are, but to instead specify 'org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup'.

  • 7. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    Sorry for the late reply - I was on holidays. I surely appreciate help from knowledgeable people !

     

    Line 47 is waaaaaaay off.

     

    Glad I'm waaaaaaay off. At least somebody sees something wrong. :-) Not that I didn't try anything else.

     

    Line 46 is "ok", depending upon your style of transaction control.  You might need 'org.hibernate.transaction.JTATransactionFactory' or 'org.hibernate.transaction.CMTTransactionFactory'.  But you have not given enough info here to tell.

     

    I'm afraid I don't have more than the Spring configuration file. What details do you need ?

    In lIne 47 you are trying to pass a Infinispan class as a HIbernate contract.  Thats not going to work.  And in 4.x, we (Hibernate) moved away from the generally too-simplistic notion of a "TransactionManager lookup".  Instead, we now have a contract org.hibernate.service.jta.platform.spi.JtaPlatform which describes all aspects of JTA within the given environment.  So the hibernate.transaction.manager_lookup_class is actually deprecated.  If specified, Hibernate will try to map the legacy implementation names to the newer JtaPlatform implementations.  But you specified something completely different here.  So you have 2 options.  The better solution is to use the newer 'hibernate.transaction.jta.platform' setting to name the impl you want to use (org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform here I guess?). 

     

    Do you mean it's not specifying the property ? Because if it's removed I'm getting the classic tm-not-found-exception:

     

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.infinispan.CacheException: This is transactional cache but no transaction manager could be found. Configure the transaction manager lookup properly.

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

              at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)

              ... 29 more

    Caused by: org.infinispan.CacheException: This is transactional cache but no transaction manager could be found. Configure the transaction manager lookup properly.

              at org.infinispan.factories.TransactionManagerFactory.construct(TransactionManagerFactory.java:80)

              at org.infinispan.factories.AbstractComponentRegistry.getOrCreateComponent(AbstractComponentRegistry.java:286)

              at org.infinispan.factories.AbstractComponentRegistry.invokeInjectionMethod(AbstractComponentRegistry.java:246)

              at org.infinispan.factories.AbstractComponentRegistry.access$000(AbstractComponentRegistry.java:83)

              at org.infinispan.factories.AbstractComponentRegistry$Component.injectDependencies(AbstractComponentRegistry.java:790)

     

    The other possibility is to still use hibernate.transaction.manager_lookup_class as you are, but to instead specify 'org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup'.

     

    Added the dependency

     

       <dependency>

          <groupId>org.jboss.jbossts</groupId>

          <artifactId>jbossjta</artifactId>

          <version>4.16.4.Final</version>

        </dependency>

     

    Because it couldn't find *arjuna*TransactionManager class. I assumed it comes from the jbossjta dependency.

     

    It started without an exception ! BY JOVE ! Now I have to check this also works with the main application...

     

    Is there a way to tell everybody's using the same transaction manager ?

  • 8. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Steve Ebersole Apprentice

    I'm afraid I don't have more than the Spring configuration file. What details do you need ?

     

    Well I know nothing about Spring, so I cannot help you there.  As I mentioned there are 2 JTA-related setups.  The first, JTATransactionFactory, uses  javax.transaction.UserTransaction to interact with the JTA environment.  The second, CMTTransactionFactory, uses javax.transaction.TransactionManager to interact with the JTA environment.  If neither you nor Spring are using the Hibernate transaction API (org.hibernate.Transaction) or your application is using JEE CMT, you should use CMTTransactionFactory.  Otherwise you should use JTATransactionFactory.  But again, having Spring in the mix here might change some of that.  You should probably ask on Spring forums or use trial-n-error

     

     

    In lIne 47 you are trying to pass a Infinispan class as a HIbernate contract.  Thats not going to work.  And in 4.x, we (Hibernate) moved away from the generally too-simplistic notion of a "TransactionManager lookup".  Instead, we now have a contract org.hibernate.service.jta.platform.spi.JtaPlatform which describes all aspects of JTA within the given environment.  So the hibernate.transaction.manager_lookup_class is actually deprecated.  If specified, Hibernate will try to map the legacy implementation names to the newer JtaPlatform implementations.  But you specified something completely different here.  So you have 2 options.  The better solution is to use the newer 'hibernate.transaction.jta.platform' setting to name the impl you want to use (org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform here I guess?). 

     

    Do you mean it's not specifying the property ? Because if it's removed I'm getting the classic tm-not-found-exception:

     

    Well I never said to remove that setting.  I said to use a different one: hibernate.transaction.jta.platform

     

    As for the dependency, well yes, if you want to use JBossTS you will need to add dependency to its artifact.  JBossTS used to be called Arjuna.  The classes still use the arjuna package names.

     

     

    It started without an exception ! BY JOVE ! Now I have to check this also works with the main application...

     

    Is there a way to tell everybody's using the same transaction manager ?

     

    Hard to say, thats a function of your runtime environment which here is Spring. 

  • 9. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    Unfortunately Spring's forums are incommunicado. Even when bumping regularly. So really...

     

    Both the following work - but not in Netbeans. They do in IntelliJ. :-)

    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>

    <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform</prop>

     

    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>

    <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup</prop>

     

    So I'll have a try today - change the settings and run the battery of tests we have here. Something should go wrong I would think.

     

    Many thanks indeed for your advice. :-) I'll keep you posted !

  • 10. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    It all runs without an exception but doesn't roll back the transactions. The first integration test runs successfully. Data is really committed into the database. But then everything should be rolled back for the next tests. Which does not happen as the data is still there.

     

    This is the case for both the configurations. The factory class has to be the JTA one. Otherwise I'm getting an exception suggesting that joining a transaction managers does not work.

     

    Close, but no sigar... :-(

  • 11. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Steve Ebersole Apprentice

    How are you managing the transactions?  I have asked you this a few times now

     

    And rolling back as means of test clean up?  Really?  Thats just asking for trouble.

  • 12. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    How are you managing the transactions?  I have asked you this a few times now

     

    Sorry about that. Well, the point is that in Spring you don't do that explicitely. Only by means of annotations. Which makes is immensely easy to use. Also the propagation goes with the annotations. For example:

     

      @Transactional(propagation = Propagation.REQUIRED)

      public T save(final T entity) {

        final T savedEntity = jpaTemplate.merge(entity);

        if (savedEntity.getId() == null) {

          throw new IllegalStateException("Saved entity w/o primary key ! " + entity.toString());

        }

        return savedEntity;

      }

     

    The @Transactional means a transaction is needed before calling this method. And committed once it returns. Or rolled back when an exception occurs. Subsequent method calls take the transaction with them. Unless the called method is annotated with @Transaction; to cause a divergence in the transaction propagation.

     

    As such in Spring application you should never see code asking the entity manager to create a transaction. This is done for you. Hence the popularity of using Spring also for that.

     

    The whole shabang is pre-configured in the xml file included in this thread - the application context file. And each element is a "bean" in the Spring-lingo.

     

    And rolling back as means of test clean up?  Really?  Thats just asking for trouble.

     

    I admit transactions are not made with testing in mind. :-) But then again, many developers do it that way. For Spring it's even the precognized way. You annotate the unit tests to use the test running of Spring. And there you go - it rolls back the database. I honestly never heard a complaint about this.

     

    That doesn't mean I should ignore the advice from knowledgeable people. :-) Why is this asking for trouble. It should also work that way. Doesn't it ?

  • 13. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Thomas Struntz Newbie

    Did you manage to get this to work?

     

    I have following configuration:

     

                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.InfinispanRegionFactory</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
                <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform</prop>

     

    this works however transactions are automatically terminted due to a timeout that I don't know were to set it?

     

    WARN  com.arjuna.ats.arjuna - ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff0a411c11:8b9:50a3361a:2 in state  RUN

    WARN  com.arjuna.ats.arjuna - ARJUNA012095: Abort of action id 0:ffff0a411c11:8b9:50a3361a:2 invoked while multiple threads active within it.

    WARN  com.arjuna.ats.arjuna - ARJUNA012108: CheckedAction::check - atomic action 0:ffff0a411c11:8b9:50a3361a:2 aborting with 1 threads active!

    WARN  com.arjuna.ats.arjuna - ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffff0a411c11:8b9:50a3361a:2

    ERROR org.infinispan.interceptors.InvocationContextInterceptor - ISPN000136: Execution error

    java.lang.IllegalStateException: Transaction TransactionImple < ac, BasicAction: 0:ffff0a411c11:8b9:50a3361a:2 status: ActionStatus.ABORTED > is not in a valid state to be invoking cache operations on.

  • 14. Re: Working example stand-alone Spring/Hibernate/Infinispan ?
    Jan Goyvaerts Newbie

    unfortunately... I was kind of hoping somebody of Hibernate would help throught it.

     

    I've got discusions elsewhere also - stuck also.

1 2 Previous Next