-
1. Re: jboss-5.1.0.GA entity ejb 2.1 cmp query to DB every get call of function
wdfink Apr 23, 2014 4:53 PM (in response to webpurush)Moved to a better space
-
2. Re: jboss-5.1.0.GA entity ejb 2.1 cmp query to DB every get call of function
wdfink Apr 23, 2014 4:56 PM (in response to webpurush)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
webpurush Apr 23, 2014 5:41 PM (in response to wdfink)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
wdfink Apr 24, 2014 5:00 AM (in response to webpurush)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.