3 Replies Latest reply on Feb 27, 2009 5:03 AM by Ronald K.

    Advice setting JBoss Cache up loading from hibernate and rep

    Ian Jones Newbie

      Hi,

      I'm new to JBoss Cache, but having read a lot about it, it seems there are many features that would be useful to me and would simplify my architecture, so I'm going to give it a go. But first I'm looking for some advice about my particular situation. I have a number of applications with the following architecture:



      So there is one server connected to the database. On start up, the GUIs request initial load of data from the server, and then the server publishes to all GUIs any updates it receives from any of the GUIs.

      I'd like to see if I can replace it with the following JBoss Cache architecture:



      The benefits are obvious - less yellow boxes, means less code I write :-).

      I'd like advice about how to set this up. It looks rather like '9.5.3 Replicated Caches With Only One Cache Having A Store' from the docs.

      I've read that you can set JBoss Cache up as a second level cache for Hibernate , which would do all the plumbing between hibernate and JBoss Cache for me. However, then I guess the cache is managed by Hibernate, not by me. I guess this would mean that if I update the cache in the GUI, and it gets replicated to the server, this won't get picked by hibernate and won't get persisted.

      From what I've read, I think I'd need to write a bespoke CacheLoader for my hibernate objects. It looks like there used to be a hibernate cache loader
      in jboss cache. What happened to that?

      Am I on the right lines?

      Thanks,
      Ian

        • 1. Re: Advice setting JBoss Cache up loading from hibernate and
          Brian Stansberry Master

          You're correct that using JBC as a Hibernate Second Level Cache isn't what you're looking for.

          The HibernateCacheLoader class you linked was never part of JBoss Cache. It was part of JBoss Portal. Looks like it was an implementation of a concept similar to what you are talking about -- implement the JBC CacheLoader interface in such a way that Hibernate persists the cached data to regular database tables. This differs from the standard JDBCCacheLoader that comes with JBC. JDBCCacheLoader persists data in a table whose schema matches JBC's requirements but is largely useless for others who need to see the data (e.g. the cached data map is stored as a serialized blob).

          A CacheLoader based on Hibernate would need to understand what data is being put into the cache where so it knows how work with Hibernate to persist it. So, it's a custom thing for you to write -- a yellow box on your graphic. ;)

          http://anonsvn.jboss.org/repos/portal/tags/JBoss_Portal_2_2_0/core/src/main/org/jboss/portal/core/security/store/HibernateCacheLoader.java points to the source for the JBoss Portal code whose javadoc you linked. Perhaps that will give you some ideas on how to implement such a thing.

          • 2. Re: Advice setting JBoss Cache up loading from hibernate and
            Ian Jones Newbie

            Hi Brian,

            Thanks for your helpful response. You are absolutely correct - the reason I'm looking at doing this is that there are other (read only/reporting) users of the data in the database, who need it in a useful format and not in serialised blobs.

            I'll have a go at writing my own CacheLoader for my Hibernate objects, and I'll post back to let you know how I go.

            Cheers,
            Ian

            • 3. Re: Advice setting JBoss Cache up loading from hibernate and
              Ronald K. Newbie

              Hi Ian,

              I've an identical application architecture, but only with one GUI attached. My current approach is also based on JMS transporting POJO's from and to the a JBossAS using Hibernate as persistence provider.

              I was about to implement a system, that does all the sync stuff between the client and the server (I'm working with a quite large data-model; one data-model instance may consist of up to 250,000 entities; so load/update on demand, eviction of unused entities is an important point), when I was pointed to JBoss Cache.

              I came to the same conclusion, that I would need to implement a cache loader that performs the translation between the jboss cache and the hibernate operated data base.

              Did you have any success so far?

              Best Regards,
              Ron