12 Replies Latest reply on Jan 19, 2011 12:26 PM by sudheerk84

    Using Infinispan with transaction manager on standalone code

    sudheerk84

      I am currently using spring JDBC  for Mysql database.  Also i am using spring transaction manager for maintaing database transactions.

       

      My business requirement is as follows

       

      I am planning to use JBoss cache as my caching layer . Any calls to the data Access layer shoudl first check if teh DAO are present in the cache , if not then has to query the cache. To achive this i am planning to write some custom code. Is there anything already inbuilt in infinispan ?

       

       

      Similarly whenever i commit anything  i want to ensure that data is commited into Mysql database(using spring jdbc) and the infisnispan cache is also updated  in a single transaction. Is this possible ?

       

      I do not much expirience on JTA but have used spring transaction management for handling database transactions.

       

      Any help is really appreciated ?

        • 1. Using Infinispan with transaction manager on standalone code
          manik

          Why not just use Hibernate and Infinispan as a second level cache for Hibernate?  It will make your life much easier.

          1 of 1 people found this helpful
          • 2. Using Infinispan with transaction manager on standalone code
            sudheerk84

            We wanted much more control over the JDBC statements we issue and wanted a light weight jdbc framework. So we have gone ahead and already started implementing our code with spring JDBC.

             

             

            Now we are looking for a solution wherein we can commit into teh database and cache in a single transaction ? Is this possible with any transaction manager provided by jboss/spring ?

            • 3. Using Infinispan with transaction manager on standalone code
              manik

              Yes it is possible, it will just mean a fair amount of integration code by yourself.  You'd need to check the cache, if the entry exists use it, else run your DB query and store the result back in the cache using putForExternalRead()

               

              You would also need to handle value updates by updating the cache. 

               

              Is this a single-server or clustered environment?

              • 4. Using Infinispan with transaction manager on standalone code
                sudheerk84

                Its a clustered environment. Ans we are looking for a distributed cache.

                • 5. Using Infinispan with transaction manager on standalone code
                  sudheerk84

                  Thanks a lot for such quick response

                   

                  If I get ur response right,

                   

                  First of my usecases can be achived by writing some custom code from my side, which gives me flexibility of fetching from database and then updating  the cache.Subsequent reads will take from cache.

                   

                  My second usecase when i do a write into database and cache I need a transactional behaviour.  Is this also possible?

                   

                  Is so which is the transaction manager i can use for mainting transactions across my database(spring jdbc) and  infinispan ?

                  • 6. Using Infinispan with transaction manager on standalone code
                    mircea.markus
                    My second usecase when i do a write into database and cache I need a transactional behaviour.  Is this also possible?

                    I guess this means you either write in both or in non. Yes, possible - you'll just have to make sure that Infinispan "sees" the used transaction manager. This is configured through transactionManagerLookupClass attribute of the "transaction" config element.

                    • 7. Using Infinispan with transaction manager on standalone code
                      manik

                      Any JTA compliant transaction manager can be used.  See the Infinispan docs on JTA integration.  JBossTM is a good choice.

                      • 8. Using Infinispan with transaction manager on standalone code
                        sudheerk84

                        Thanks a lot for all the replies. I will have a look at JBossTM and publish my finding once i get transaction working across spring jdbc and infinispan.

                        • 9. Using Infinispan with transaction manager on standalone code
                          sudheerk84

                          I started using atomikos transaction manager. I am able to get transaction with teh datasource but when trying to test the behaviour across  infinispan i get a exception.

                           

                           

                          java.lang.ClassCastException: com.atomikos.icatch.jta.UserTransactionManager cannot be cast to org.infinispan.transaction.lookup.TransactionManagerLookup

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

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

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

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

                           

                           

                          This is what i have in teh default section of my cache config file.

                           

                           

                             <default>

                           

                                <jmxStatistics enabled="true"/>

                           

                                <clustering mode="replication">

                           

                                   <stateRetrieval

                                      timeout="20000"

                                      fetchInMemoryState="false"

                                      alwaysProvideInMemoryState="false"

                                   />

                           

                                   <sync replTimeout="20000"/>

                           

                                </clustering>

                               

                                 <transaction 

                                      transactionManagerLookupClass="com.atomikos.icatch.jta.UserTransactionManager"

                                      syncRollbackPhase="false"

                                      syncCommitPhase="false"

                                useEagerLocking="false"/>

                               

                            </default>

                          • 10. Using Infinispan with transaction manager on standalone code
                            sudheerk84

                            i just decompiled teh source to check the code

                             

                                  if (this.configuration.getTransactionManagerLookupClass() != null) {

                                    lookup = (TransactionManagerLookup)Util.getInstance(this.configuration.getTransactionManagerLookupClass());

                                  }

                                }

                             

                            I get a feel that there is a casting done to org.infinispan.transaction.lookup.TransactionManagerLookup. Isnt this a bug ?

                             

                            Since it says  "Any JTA compliant transaction manager can be used."  How can we expect a JTA compaint transaction manager to implement infinispan specific interface ?

                            • 11. Using Infinispan with transaction manager on standalone code
                              mircea.markus

                              transactionManagerLookupClass attribute is wrong. It should not tell what TM you are using, but rather how too look it up. I suggest taking a look at the DummyTransactionManagerLookup implementation.

                              • 12. Using Infinispan with transaction manager on standalone code
                                sudheerk84

                                Thanks , my mistake . I totally misunderstood the attribute property.

                                 

                                I have now writen my own look up class which gets teh spring container instantiated transaction manager(atomikos) and it works fine.

                                 

                                Thanks again for such quick reply.