when is ejbStore() called?

Discussions

EJB design: when is ejbStore() called?

  1. when is ejbStore() called? (6 messages)

    When does ejb container perform database update by calling ejbStore()? In our system, we have both Java and C++ layers. Each layer will update database at any time. How can I ensure that the entity beans' data will be stored in database quick enough? Thanks.

    Threaded Messages (6)

  2. when is ejbStore() called?[ Go to top ]

    When does ejb container perform database update by calling ejbStore()? In our system, we have both Java and C++ layers. Each layer will update database at any time. How can I ensure that the entity beans' data will be stored in database quick enough? Thanks.
  3. when is ejbStore() called?[ Go to top ]

    When does ejb container perform database update by calling ejbStore()? In our system, we have both Java and C++ layers. Each layer will update database at any time. How can I ensure that the entity beans' data will be stored in database quick enough? Thanks.
  4. when is ejbStore() called?[ Go to top ]

    ejbStore() will be invoked before passivation, and also at the end of your transaction. Basically shorter transactions will update database very often, the performance may be degraded due to recent database updates. It depends on your business logic to decide which kind of Isolation parameter is right for your entity beans.
  5. when is ejbStore() called?[ Go to top ]

    The EJB spec does not specify exactly when ejbStore is called. The decision is left in the hands of the container. It is only guaranteed that the container will invoke ejbStore in the end of a transaction or before passivation (except for some "tricky" cases, see below). Generally if have several layers accessing the same database then there are two options:

    1. The two layers share a transaction (using XA). In that case the only "clean" way I know to have them see each-other's changes is to have them both access the database through the entity beans. A C++ layer can invoke entity beans directly via CORBA, go through a session bean via CORBA or use messaging/web-services/...
    If this is unacceptable for you, there is one workaround I can think of. The EJB spec (subsection 12.3.2) requires that when you invoke a finder method on a bean-managed entity bean, the container synchronize all beans associated with the calling transaction by invoking ejbStore on them. This is needed in order to ensure that finder methods see up-to-date values when executing SQL queries. So, you can call some "dummy finder" that does nothing (and returns an empty collection) to force the container to synchronize all the beans in your transaction context.
    I don't know of any similar "trick" for forcing the container to refresh the cache (i.e., call ejbLoad). Anyway this is really a "dirty trick", I wouldn't use it unless there are no alternatives.

    2. The two layers use seperate transactions. In that case, no matter when ejbStore is called, the C++ layer won't see changes made by the EJB layer until the transaction commits. You have to commit your transaction in the EJB layer before the C++ layer reads the data (perhaps even before the C++ layer starts it's transaction, depending on your isolation level).

    Regards
    Gal
  6. when is ejbStore() called?[ Go to top ]

    ejbStore() saves your bean's instance fields to underlying data storage

    Container decides to call load() and store() at will.

    Developer never explicitly calls ejbLoad() and ejbStore() ie, no need to
    synchronize the objects to data storage

    The frequency with which beans are synchronized with the storage is dictated
    by Transactions

    As some one pointed out, ejbStore is sure to be called before you come out of the transaction just to synchronize the bean's fields with that of the DB.
  7. when is ejbStore() called?[ Go to top ]

    ejbStore() saves your bean's instance fields to underlying data storage

    Container decides to call load() and store() at will

    Developer never explicitly calls ejbLoad() and ejbStore() ie, no need to
    synchronize the objects to data storage.

    The frequency with which beans are synchronized with the storage is dictated
    by Transactions


    As some one pointed out correctly, ejbStore() will be called before the end of the transaction just to synchronize with DB.