4 Replies Latest reply on Apr 9, 2009 6:55 PM by brian.stansberry

    JBC Strategie with JPA/Hibernate

      Hi all,

      reading section 9.5.4 of the guide "replicated caches with each cache having its own data store" a question arises:

      - Using JPA/Hibernate, would it possible to have two nodes (or even more) in a cluster (one db per node), and operate the same way section 9.5.4 describes?? That is, keep two DBs in sync through the cache ?

      - If not possible, I must adhere to using just one db for the whole cluster or using one db per node and assume db's will go out of synch ??

      What's the best strategie ??

        • 1. Re: JBC Strategie with JPA/Hibernate
          manik

          If you are referring to a cache loader, I can't imagine why you would use a cache loader if you are using JBC with Hibernate, since Hibernate already provides persistence.

          Using cache loaders with JBC is really for cases where you want cached in-memory state to be persisted (e.g., to disk or a DB) so it survives restarts and it can be evicted from memory when the cache hits certain thresholds.

          In the case of a Hibernate 2nd level cache, this is unnecessary since any state in the cache already exists in Hibernate.

          • 2. Re: JBC Strategie with JPA/Hibernate

            Thanks Manik,

            I was really looking for a solution to have two clustered nodes with one db each, and get the dbs in synch in the same way the cache is.

            If I'm using load balancing, app calls will be balanced between nodes. Cache data will be in synch, but db data will NOT. Imaging tx1 goes to node1 to modify customer 1. Either by invalidation or replication, the two caches will be in synch, but just db1 will hold the modification to customer 1, while db2 won't know about that modification.

            Should I be using a third party software to get the two dbs in synch??

            • 3. Re: JBC Strategie with JPA/Hibernate

              The following sentence makes me believe the only consistent cache strategy is using a single database for all nodes in the cluster. It is in "Chapter 2. Core Concepts" of hibernate 3.3.1 guide:

              Concurrent cache updates of the same entity anywhere in the cluster should not be possible, as Hibernate will acquire an exclusive lock on the database representation of the entity before attempting to update the cache.

              Should I be using the same DB for all nodes?
              Is there any solution you can think of to be using one DB per node and have the DBs in synch as the cache is ?

              • 4. Re: JBC Strategie with JPA/Hibernate
                brian.stansberry

                If you want multiple DBs, you either:

                1) Rely on the clustering capabilities of your database vendor.

                2) Use middleware like HA-JDBC[1] or Sequoia.

                Trying to use the JBoss Cache used as the Hibernate 2nd Level Cache to keep your DBs in sync is definitely not the way to go.

                [1] http://ha-jdbc.sourceforge.net . Founded/led by my colleague in the JBoss AS Clustering team, Paul Ferraro. See some links on the bottom of that page for other related tech.