4 Replies Latest reply on Apr 24, 2014 5:00 AM by Wolf-Dieter Fink

    jboss-5.1.0.GA entity ejb 2.1 cmp query to DB every get call of function

    drew patl Newbie

      Jboss version:jboss-5.1.0.GA

      JDK version:jdk1.6.0_05

      database: oracle10g

      linux: fedora

       

      I am using ejb 2.1 entity bean in my application. It is container managed bean. It is accessing one of the table information. I have corresponding get methods for every column access. When i have enable log for cmp bean. I see it execute query for every get call function. I have analyze database side also, It calls query multiple times based on get call function. I have tried all commit option A, B, C, D from jboss.xml but seems like still it is calling query for every get function. How to stop calling query for every get function. Also How to know from log which commit option i am using ( using log4j). I have tried all the possible combination but didn't work so far. your help would be valuable.

       

      thanks

      drew

        • 2. Re: jboss-5.1.0.GA entity ejb 2.1 cmp query to DB every get call of function
          Wolf-Dieter Fink Master

          That depends on more ...

           

          Could you show the Entity configuration (ejb-jas , jbosscml-jdbc and jboss.xml)

          Did you change the container configuration and which one you use?

          How do you call the different getter? If you use a SLSB you need to have this method transactional as Entities must accessed in a transaction.

          • 3. Re: jboss-5.1.0.GA entity ejb 2.1 cmp query to DB every get call of function
            drew patl Newbie

            Thanks Wolf-Dieter,

               Following is my details

             

             

            <!-- jboss.xml -->

            <?xml version="1.0" encoding="utf-8"?>

            <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_5_0.dtd">

            <jboss>

              <enterprise-beans>

              

              <entity>

              <ejb-name>J1Address</ejb-name>

              <jndi-name>com.test.EJB.Entity.Address</jndi-name>

              <read-only>True</read-only>

                        <clustered>True</clustered>           

              </entity>

              </enterprise-beans>

              <container-configurations>

                    <container-configuration >

                        <container-name>Standard CMP 2.x EntityBean with cache invalidation</container-name>

                        <commit-option>D</commit-option>

                    </container-configuration>

                 </container-configurations>

            </jboss>

             

             

             

             

             

             

            <!-- jbosscmp-jdbc.xml -->

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"

              "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

            <jbosscmp-jdbc>

              <defaults>

              <datasource>dbpool</datasource>

              <datasource-mapping>Oracle9i</datasource-mapping>

              </defaults>

              <enterprise-beans>

              

              <entity>

              <ejb-name>Address</ejb-name>

              <create-table>false</create-table>

              <table-name>ADDRESS</table-name>

              <cmp-field>

              <field-name>ownerType</field-name>

              <column-name>OWNER_TYPE</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>objectId</field-name>

              <column-name>OBJECT_ID</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>addressTag</field-name>

              <column-name>ADDRESS_TAG</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>status</field-name>

              <column-name>STATUS</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>firstName</field-name>

              <column-name>FIRST_NAME</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>middleName</field-name>

              <column-name>MIDDLE_NAME</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>lastName</field-name>

              <column-name>LAST_NAME</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>companyName</field-name>

              <column-name>COMPANY_NAME</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>address1</field-name>

              <column-name>ADDRESS1</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>address2</field-name>

              <column-name>ADDRESS2</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>city</field-name>

              <column-name>CITY</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>state</field-name>

              <column-name>STATE</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>zip</field-name>

              <column-name>ZIP</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>countryCode</field-name>

              <column-name>COUNTRY_CODE</column-name>

              </cmp-field>

              <cmp-field>

              <field-name>email</field-name>

              <column-name>EMAIL</column-name>

              </cmp-field> 

              </entity>

              

              </enterprise-beans>

            </jbosscmp-jdbc>

             

             

            <!-- ejb-jar.xml -->

             

             

            <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

             

             

             

             

            <!-- Generated XML! -->

             

             

            <ejb-jar>

              <enterprise-beans>

                

                <entity>

                  <ejb-name>Address</ejb-name>

                  <home>com.test.EJB.Entity.AddressHome</home>

                  <remote>com.test.EJB.Entity.AddressRemote</remote>

                  <ejb-class>com.test.EJB.Entity.Address</ejb-class>

                  <persistence-type>Container</persistence-type>

                  <prim-key-class>com.test.EJB.Entity.AddressPK</prim-key-class>

                  <reentrant>False</reentrant>

                  <abstract-schema-name>J1Address</abstract-schema-name>

                  <cmp-field>

                    <field-name>ownerType</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>objectId</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>addressTag</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>status</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>firstName</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>middleName</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>lastName</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>companyName</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>address1</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>address2</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>address3</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>city</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>state</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>zip</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>countryCode</field-name>

                  </cmp-field>

                  <cmp-field>

                    <field-name>email</field-name>

                  </cmp-field>

                  

               

                  <query>

                    <query-method>

                      <method-name>findByOwnerAddressTag</method-name>

                      <method-params>

                        <method-param>java.lang.String</method-param>

                        <method-param>java.lang.Long</method-param>

                        <method-param>java.lang.String</method-param>

                      </method-params>

             

             

                    </query-method>

             

             

                    <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(o) FROM Address o WHERE ((o.ownerType = ?1) AND (o.objectId = ?2) AND (o.addressTag = ?3))]]></ejb-ql>

                  </query>

                </entity>

              

              </enterprise-beans>

             

             

              <assembly-descriptor>

               

                <container-transaction>

                  <method>

                    <ejb-name>Address</ejb-name>

                    <method-name>*</method-name>

                  </method>

                  <trans-attribute>Required</trans-attribute>

                </container-transaction>

                

              </assembly-descriptor>

             

             

            </ejb-jar>

             

             

             

             

             

             

             

             

            <!-- i am calling from jsp like following -->

             

             

            try {

                    Context ctx = new InitialContext();

                AddressHome hAddr = (AddressHome)ctx.lookup("com.test.EJB.Entity.Address");

              AddressRemote rAddr = hAddr.findByPrimaryKey(new AddressPK("buyer",new Long("1184144"),"bill"));

             

                 firstName = rAddr.getFirstName();

                 lastName = rAddr.getLastName();

             

              } catch (Exception e) {

             

              }

            • 4. Re: jboss-5.1.0.GA entity ejb 2.1 cmp query to DB every get call of function
              Wolf-Dieter Fink Master

              I guess that this is related to a different context/transaction and the container decide to reload the entity.

              From my experience you should use transfer objects if you need more than one attribute from an entity, this will be faster as more attributes you load as each entity bean call will have costs (not only if the DB is involved) and I measured that it is faster until two attributes are loaded.