2 Replies Latest reply: Aug 22, 2010 8:33 AM by 807580 RSS

    Are EJB ( entity beans) are cached ?

    807580
      Are EJB ( entity beans) are cached ?

      I have a doubt here . As per my understanding , the entity beans are cached from the database. In that case , If I delete a row in the database by an external application ( say using TOAD tool) , how the Entity bean will be updated / reloaded ? Entity bean will be out of sync then .

      Application server : weblogic/webspehere .
        • 1. Re: Are EJB ( entity beans) are cached ?
          801449
          Yes the entities are cached in the persistence context and the second level cache as well (if it's configured to be used) and if you manually change the database then it will be out of sync. (The same applies to native queries as well by the way...).
          You can use the refresh method of the EntityManager interface to read new values from the database (if you expect it to be out of sync), and use locks to prevent others from changing your data while the application is performing actions in a transaction.
          • 2. Re: Are EJB ( entity beans) are cached ?
            807580
            >
            You can use the refresh method of the EntityManager interface to read new values from the database (if you expect it to be out of sync), and use locks to prevent others from changing your data while the application is performing actions in a transaction.
            Did you mean I have to write code for this ? can't be made it automatic refresh by the container ? Is there any settings I can configure so that container can do it by itself proactively ?

            Also, using locks ...is this a container settings or I need to configure myself in ejb-jar.xml ? Could you please shed some light here ?