caching data with entity beans

Discussions

EJB design: caching data with entity beans

  1. caching data with entity beans (11 messages)

    In other projects we have cached data from the database
    in read-only singletons. I am not sure how to do this in EJB. I figure that we can create Entity beans that have a <cache-strategy> set to Read-Only and persistence <db_is_shared> set to false. This should enable a CMP entity bean to be cached, but how de we get all
    the rows loaded efficiently at startup without having to hit the database once for every row? Does anyone have the answer?

    Threaded Messages (11)

  2. caching data with entity beans[ Go to top ]

    With the help of Connection Pooling u can have a connection and can use that only for this purpose ,means to say simply have a con object and make it persistent and without returning that con u can have the states of ur Entity Bean object.
              Rajeev
  3. caching data with entity beans[ Go to top ]

    I am sorry, but I do not understand your solution.
  4. caching data with entity beans[ Go to top ]

    There is no value using entity bean for this, use stateless session instead.
  5. caching data with entity beans[ Go to top ]

    Where will you cache data in stateless beans? Only in static fields as I think...

    As for the read-only beans, this is the feature of WebLogic server (only?). So to fill the cache at startup you may use weblogic-specific Startup-classes (method of startup class is called by weblogic during server startup process).
  6. caching data with entity beans[ Go to top ]

    Not necessary, you can initialize the object fields in the ejbcreate() or setEntityContext() and never worry about
    passivation/activation issues, stateless SB means no client
    specific state, not means no state itself.
  7. caching data with entity beans[ Go to top ]

    Use entity bean if you have some share data that need to
    be accessed(read and write) concurrently and you want
    to ensure the ACID properties.
  8. caching data with entity beans[ Go to top ]

    This makes sense. Thanks.
  9. caching data with entity beans[ Go to top ]

    Wouldn't this mean that every instance in the pool
    would have to hit the database and what about refreshing the data periodically.
  10. caching data with entity beans[ Go to top ]

    I am afraid so, you don't want a singleton stateless
    session bean, do you:-)
    About refreshing, it depend on your requirements,
    one way to do this is create a timer manually:
    reload()
    {
    ...//read data from backend
    last_refresh_time=currenttime();
    }


    foo()
    {
       if (currenttime()-last_refresh_time>REFRESH_INTERVAL)
           reload();
       ....//serving client here
    }



  11. Even with a startup class, won't the ejbLoad() be called for every row making it much less efficient than a
    single select statement?
  12. caching data with entity beans[ Go to top ]

    I currently have it in a stateless bean. I ultimately
    wanted to put more data access in entity beans to stick
    with a common approach. At this point this seems unlikely.
    Every time I want to move to Entity Beans there are reasons why we shouldn't and ambiguous information regarding them. Do you know under what conditions the use of entity beans is definitely a good idea?