4 Replies Latest reply on Mar 27, 2005 3:14 AM by pflapf

    performance problem with read-only entity beans

    pflapf

      Hi!

      I'm unsure about the following scenario:

      I have a stateless session bean. this session bean calls multiple different entity beans. every entity bean is deploy twice, once r/o and once r/w.
      If the session bean only tries to read from the database it uses the local home interfaces for the r/o beans. If the session bean must write to the database it uses the local home interfaces for the r/w beans. I think that isn't unsual yet.
      Now when read from the database to get a bean, e.g. with findByPrimaryKey() the server.log shows the appropriate SQL select statement like "select t.primary_key from anytable t where t.field = value".
      When I later access the entity with, e.g. the bean.getPrimaryKey() method, the whole content is loaded via sql, the server.log shows "select t.field, t.another_field from anytable t where t.primary_key = ...". I think that's lazy loading and it's fine for me.
      Now there's a difference between r/o and r/w beans. For subsequent get-accesses to the beans fields, e.g. getField(), the r/w bean does not send any SQL statement. Everything seems to be cached. Any getField() call to the r/o bean forces the bean to be reloaded completely via SQL, so another "select t.field, t.another_field from anytable t where t.primary_key = ..." is performed. I don't know why. I think, there's no reason to do that. I thought, r/o beans would be a bit faster but with all the SQL statements to be performed it's a lot slower than r/w entity beans.
      Anyone out there to help me?

      --- jbosscmp-jdbc.xml ---

      <ejb-name>entitybeans_rw_DS_MAPSHome</ejb-name>
      <table-name>ds_maps</table-name>
      <cmp-field>
      <field-name>mapId</field-name>
      <column-name>MAP_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>localId</field-name>
      <column-name>LOCAL_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>remoteId</field-name>
      <column-name>REMOTE_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>targetId</field-name>
      <column-name>TARGET_ID</column-name>
      </cmp-field>



      <ejb-name>entitybeans_ro_DS_MAPSHome</ejb-name>
      <table-name>ds_maps</table-name>
      <cmp-field>
      <field-name>mapId</field-name>
      <column-name>MAP_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>localId</field-name>
      <column-name>LOCAL_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>remoteId</field-name>
      <column-name>REMOTE_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>targetId</field-name>
      <column-name>TARGET_ID</column-name>
      </cmp-field>


      --- jboss.xml ---

      <ejb-name>entitybeans_rw_DS_MAPSHome</ejb-name>
      <local-jndi-name>entitybeans.rw.DS_MAPSHome</local-jndi-name>


      <ejb-name>entitybeans_ro_DS_MAPSHome</ejb-name>
      <read-only>true</read-only>
      <local-jndi-name>entitybeans.ro.DS_MAPSHome</local-jndi-name>



      all other config is default.

      Thanks,

      Dirk