5 Replies Latest reply on Nov 21, 2013 3:48 PM by rareddy

    TEIID with hibernate, drools and infinispan cache

    ankitkrsingh

      Hi Team,

       

      I want to expose web services using TEIID which should perform CRUD operation using hibernate with infinispan cache. I would want to configure infinispan cache server in different JVM so require hotrod client to connect to cache server. I would also want to write business rule using drools.

       

      Is it possible to acheive the above configuration?

       

      So far, I have created a SOAP webservices using TEIID designer with gererate CXF war features but don't know how to connect to hibernate for CRUD operation.

       

      Please help me by sharing some pointers to such configuration.

        • 1. Re: TEIID with hibernate, drools and infinispan cache
          rareddy

          Sure it is possible. What is not clear from your post is how are you stacking all the different components from client application to the rest of them. I see one possible integration as

           

          Client app --> Web App (you develop) --> drools --> Hibernate --> Teiid

                                                                                         |

                                                                                 Infinispan Cache

           

          Check out Teiid Quick starts, for examples with Infinispan and Drools.

           

          It would be great if you write a blog when you are done integrating all these for others to see.    

           

          Ramesh..

          • 2. Re: TEIID with hibernate, drools and infinispan cache
            ankitkrsingh

            Thanks.

             

            I would like to have

             

            Web Services ==> EJB ==> Hibernate ==> TEIID ==> Infinispan Cache

             

            But I doubt if the above sequence is correct. How will Infinispan fit into above architecture.

             

            Can EJB connect to both in parallel?

             

                 EJB ==> infinispan

            EJB ==> hibernate==> Teiid

             

            OR

             

            Can hibernate connect to teiid which in turns connects to infinispan?

             

            hibernate ==> Teiid ==> infinispan

             

            I want to have the data in sync in infinispan and teiid data base.

            • 3. Re: TEIID with hibernate, drools and infinispan cache
              rareddy

              Ankit,

               

              I want to have the data in sync in infinispan and teiid data base.

              Ok, this is what I am looking for. And "Yes" for all the answers you asked above. The question really is what is your usecase and what you are trying to achieve.

               

              Teiid is a virtual database, so data does not really reside in this layer, it always is persisted to other databases, that could be Infinispan. However the issue is, Infinispan is key/value store, so storage in relational terms is not simple.

               

              I still recommend as I did in the first reply

               

              Web Services ==> EJB ==> Hibernate ==> TEIID ==> Database like Postgres

                                                            ||

                                                        Infinispan


              Here you are using the Infinispan as second level cache for Hibernate. Since your access to the EJB is through Hibernate this makes sense. Unless, you are using Teiid for some data virtualization needs, you do not really need Teiid. i.e. If you are just using simple RDBMS, then you can just use that RDBMS underneath Hibernate and not use Teiid. But if you are connecting to multiple sources then you do need Teiid.

               

              Hope this helps.


              Ramesh..

              • 4. Re: TEIID with hibernate, drools and infinispan cache
                ankitkrsingh

                Thanks Ramesh.

                 

                I don't want to use infinispan as second level cache for hibernate(put and get into cache is handled by hibernate) rather I want to code put and get methods and have client talking to infinispan server using hot rod protocol in hibernate layer.

                 

                Using second level cache, search will be a hibernate search and most of the time will go to DB as we will have many updates and results will be invalidated from cache.

                 

                I want my code to search from cache only and not from DB and add/update/delete happens in both cache an DB. Can I code this using infinispan data grid.  I would have to ensure that up to date information is always in cache (I.e. All update flows would have to update cache and DB).

                 

                Use case:

                 

                User ==> add employee(hibernate) ==> infinispan Cache ( I want to put employee into cache so that it is read from here and not from DB)

                                                                          ==> Database(also adding into DB)

                 

                User ==> search employee(hibernate) ==> infinispan Cache (I want to get employee from cache and not from DB. With 2 level cache, employee will be loaded from DB as it is not there in cache)

                                                                         

                User ==> update employee(hibernate) ==> infinispan Cache

                                                                               ==> Database

                 

                User ==> search employee(hibernate) ==> infinispan Cache

                 

                I want infinispan cache behaving as primary DB in case of search.

                I only want to know if it is feasible and what can be the risks associated with this like how to connect to infinispan and DB(teiid VDB) from hibernate layer at the same time and how to ensure that the data is in sync.

                • 5. Re: TEIID with hibernate, drools and infinispan cache
                  rareddy

                  Ankit,

                   

                  Looks like you need to ask this question in Hibernate or Infinispan forums. I have no idea, how one could inject their custom code into hibernate (in this case your access to the Infinispan in read/create/update/delete scenarios).  And more over, you are guessing that for getting the Object back from Infinispan using Hibernate search interface, you express search query to Infinispan as effectively as you could to a Hibernate. They are not one and same. One is a ORM and another is Key/Value store. May be you want to see Hibernate OGM, this provides hibernate layer over Infinispan, but no database. You can probably configure a cache loader under Infinispan as persistent store, but do not expect the same schema as you get through Hibernate ORM.

                   

                  [1] In order for Infinispan to be the DB, you have to provide a whole relational database engine on top that which supports ACID properties for layering you showed above.

                   

                  Teiid can provide that kind of abstraction layer

                   

                                                                  Database           

                  User ==> Hibernate ==> Teiid <

                                                                  Infinispan

                   

                  but it has to deal with same issue as [1], which Teiid currently does *not* have. Or you can do

                   

                  User APP ==> Hibernate ==> Teiid ==>Database

                    ||

                  Infinispan

                   

                  In this case you are managing the MVCC, transactions etc to keep data in sync and safe. But at the end, IMO using 2nd cache seems to be optimal in your case, and would save many man months of development.

                   

                  I am also open to any other solutions others may have..

                   

                  Ramesh..