8 Replies Latest reply on Jan 20, 2012 1:28 AM by Nick .

    Hibernate + Infinispan

    Nick . Apprentice

      Can anybody give a solid example integrating Hibernate + Infinispan in Jboss AS 7 (JBoss documentation is not really giving much idea on it).


      It would be great if anyone can direct me to, the best of integrating MDC (Master Data Caching) in our project with Hibernate + Infinispan + Jboss AS7.

        • 1. Re: Hibernate + Infinispan
          Galder Zamarreño Master

          I've just updated the AS 7.1 guide with info on second level cache: https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide


          There's very little you have to do other than enabling the use of second level cache (and optionally query cache) in your persistence.xml


          Infinispan is already deployed and the container for it is already configured in the optimal way.


          I dunno what MDC is.

          1 of 1 people found this helpful
          • 2. Re: Hibernate + Infinispan
            Nick . Apprentice

            Thanks for your update Galder but i'm sorry to say that, i am not using JPA. We are using Hibernate without EJB. If you can give me some idea on how to do it would be greatful.


            MDC is just a term used call for Master Data Cache. Which means there are some customer data which will not or less frequently get updated, inserted or deleted.  We will be caching all those data eagerly or lazily. I just want to know a best machanism to acheive it. Its nothing to do with Caching framework.

            • 3. Re: Hibernate + Infinispan
              Galder Zamarreño Master

              Well Nick, the differences between Hibernate and JPA are minimal and are easily deducible by comparing hibernate and jpa configs, i.e.


              <property name="hibernate.cache.use_second_level_cache" value="true"/>




              <property name="hibernate.cache.use_second_level_cache">true</property>


              You'll have to refer to Hibernate for the rest of the config details which I imagine you already have in place in your hibernate.cfg.xml or similar.


              Obviously, no need to worry about the share cache mode since that's JPA specific.


              For MDC, what you're talking about can easily be achieved with a simple cache from a cache container specific to your application. There's some info on how to do this in https://docs.jboss.org/author/display/ISPN/Getting+Started+Guide+-+JBoss+AS+7 - But there's more things you're gonna have to take into account, for example, whether you're planning cluster it, if so, whether replication/invalidation or distribution works best for you (see cache modes in the Infinispan docu), where this information is coming from and whether you need the cache to be backed up by a persistent store, if you want to access it within a transaction or not...etc. So, the best way to do this depends on your deployment environment, how big the data set will be...etc.

              • 4. Re: Hibernate + Infinispan
                Nick . Apprentice

                Thanks Galder, I already did those things you have mentioned to enable caching in hibernate.cfg.xml but it seems like beloved JBoss AS 7 is not supporting it just like JPA. I'm facing a chain of issues related to that, which i have posted in the forum.



                And for MDC, yes we need it to be clustered & distributed. I guess this all can be handled by Infinispan itself we dont have to worry much about it other than configuring it. But do have some idea which is the best methodology to be follow to Cache such data. For example how , when, where such data to be cached.  Anyway thanks for you inputs about it, you can ignore the MDC part.

                • 5. Re: Hibernate + Infinispan
                  Galder Zamarreño Master

                  Ah, I see. I believe those issues are being addresses.


                  If the data to be cache is small and the cluster is small, replication could work pretty well. The advantage is that all nodes have the data, so access is always local. IOW, there's no need to other nodes to retrieve data. In terms of when to cache data, we've been doing some presentations on use cases of Infinispan, and when it comes to caching, you want to be caching that's either: frequently accessed, or hard to calculate. Caching is there to speed up things, so stuff that's often used is easily accessible, and stuff that's hard to calculate can be cached to avoid re-calculating. For the how, see https://docs.jboss.org/author/x/RAY5 which now contains detailed information on putForExternalRead which is particularly useful for caching use cases. I dunno about the where...

                  1 of 1 people found this helpful
                  • 6. Re: Hibernate + Infinispan
                    Nick . Apprentice

                    Thanks Galder, yes experts are there to help me but didn end up any where yet


                    Thanks for ur input and that link, will go through it. I have ennumber of doubts with respect to caching but as of now i'm putting it on hold until Jboss AS 7 Caching starts working for me. (like there must be a way to do a Cache abstraction because today infinispan, tomorrow something else).

                    • 7. Re: Hibernate + Infinispan
                      Galder Zamarreño Master

                      JSR-107 (http://jcp.org/en/jsr/detail?id=107) is moving along, so hopefully you soon won't have to bother about the abstraction either...

                      • 8. Re: Hibernate + Infinispan
                        Nick . Apprentice

                        Thats cool Galder