5 Replies Latest reply on May 14, 2007 3:40 PM by kentzhou

    How to clean or refresh EJB cache?

      Hi, I have a Web application use EJB.
      UserAccount is a BMP Entity Bean. When user login into the system, web app will put this EJB in session through other session bean.
      When user log out, clean web session.

      Then change the user account info in database, then login again. The database changes are not loaded into the EJB UserAccount, it including the old data.

      Then I need to restart JBOSS, and login again, then I can get the changes of database in EJB.

      How to get the changes of database and no need to restart JBOSS?
      JBOSS have a good cache for many thing, but I need a way to refresh the cache to get changes in database online.

      Help please.

        • 1. Re: How to clean or refresh EJB cache?
          swjackson

          sounds to me like you are not calling session.flush() if you are using CMT or you are not calling commit() for BMT.

          There is also this property you may want to look at
          hibernate.transaction.flush_before_completion=false|true

          • 2. Re: How to clean or refresh EJB cache?

            Hi, Thanks for reply.

            I think it is not related to Commit. I have tried your suggestion, but can't solve this issue.

            The problem is: when the Entity Bean is in JBOSS pool already(this is server side cache), next time if app needs the EJB, it will get from pool, but the data in database maybe changed. So question is how to Synchronize EJB with database in the pool when app get it.

            With CMP, you can use something like EntityManager.flush(), but how to do the same thing with BMP?


            • 3. Re: How to clean or refresh EJB cache?
              swjackson

              You can try EntityManager.refresh().

              You may also want to revisit your configuration( annotations, persistence properties).

              Are you manually changing the data in the database or is your Bean updating the record?

              • 4. Re: How to clean or refresh EJB cache?


                Change the data manually. same data could be changed by different apps at different time.

                EntityManager come out for EJB 3.0, but my application user EJB 1.1.

                Can you show me some demo code how to apply EntityManager for EJB 1.1?

                • 5. Re: How to clean or refresh EJB cache?

                  And my JBOSS AS is jboss 3.2.7