3 Replies Latest reply on Jul 12, 2003 6:02 AM by 11 111

    Entity Bean for caching purpose only ?

    Hermann RANGAMANA Newbie

      Hi all,

      In the project i'm currently working on, we have the classic scenario of accessing a most read-only from database and ... caching it for further request. So a colleague of mine proposed the following scenario :

      - When we receive an upcoming request, we do a findByPrimaryKey (). If the object is found, return it, otherwise perform a direct jdbc call to the database and then create an entity bean to hold the object and return it.

      So entity beans are used mainly (and exclusively) as data caching. No transaction issue, no concurrent access issue, no remote access issue, only for basic cache purpose.

      What do you think of this? Is it really worth using entity beans in this case ?

      Any comments welcomed

        • 1. Re: Entity Bean for caching purpose only ?
          marc fleury Master

          Ben yes of course,

          people think that they should use everything in the EJB. Like it is a sacred cow and you can't take anything apart. Damn it, it was written to taken apart, it was written to be eaten... I swear.

          And when you code EJB in aspects something we have been doing since Rickard came around here then you realize that using a cache object (that you can look by any name in a real cache) to store JDBC results you are really using
          1- a cmp entity bean
          2- a cached object under a string name'
          so drop all pretenses and cleanly talk to the system, in AOP JBoss 4.0 and let the system know that you want cache (give me the name) and persistence for this given java object.

          bottom line, heu ben just fucking do it

          • 2. Re: Entity Bean for caching purpose only ?
            Hezekiel Newbie

            Hrangamana

            Since Mr. Fleury seemed to be high on something ;-) (in a positive sense) I'll try to be more down to earth.

            If you want the maximum performance and entity beans as cache go with BMP (Bean managed persistence) You can specify the bean as read only (read the docs on how to do this) and left the ejbStore and ejbCreate methods unimplemented. ejbLoad could (IMHO should) be implemented in DAO (data access object) where you can write as optimized JDBC code as you like.

            If the users don't input the primary key directly there's usually no reason for findByPrimaryKey to actually look anything from database. Of course the wanted bean will be there! So just return the given Id back to the container.

            Now when the ejbFindByPrimary is invoked what happens is that if the bean with the requested id is not found from the cache the container 'creates' a bean and invokes ejbLoad on it. So it's basically the same thing that you would make a direct JDBC call 'yourself'

            The next time the same id is requested you get the bean from the cache. This can be up to tens of times more faster depending on the complexity of your cached data (from how many tables it was constructed, number of joins, etc...)

            Just implement a simple getMyCachedData() method in the bean and you have a very nice database cache!

            • 3. Re: Entity Bean for caching purpose only ?
              11 111 Newbie

              有没有jboss配置的材料
              有没有jboss部署ejb的材料
              有的话给我发一份:
              yin-bp@163.com