geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manu George <manu.t.geo...@gmail.com>
Subject Fwd: OpenEJB Question
Date Mon, 12 Dec 2005 13:35:56 GMT
Hi Gianny,

I have done all that you mentioned. I am still getting the error.I have
replicated the issue in a simple EJB,the example CMP in Ed Roman's book
Mastering EJB. I am attaching the stack trace and the plans below

17:02:05,211 WARN  [SystemExceptionInterceptor] Product
java.lang.ClassCastException
        at org.tranql.sql.jdbc.binding.StringBinding.setValue(
StringBinding.java:43)
        at org.tranql.sql.jdbc.binding.TypeConverterBinding.setValue(
TypeConverterBinding.java:93)
        at org.tranql.sql.jdbc.binding.TypeConverterBinding.setValue(
TypeConverterBinding.java:89)
        at org.tranql.sql.jdbc.JDBCQueryCommand.execute(
JDBCQueryCommand.java:64)
        at org.tranql.cache.cache.FindByPKCacheQueryCommand.execute(
FindByPKCacheQueryCommand.java:6
6)
        at org.openejb.entity.cmp.CMPFinder.execute(CMPFinder.java:98)
        at org.openejb.entity.cmp.SingleValuedFinder.execute(
SingleValuedFinder.java:80)
        at org.openejb.dispatch.DispatchInterceptor.invoke(
DispatchInterceptor.java:72)
        at
org.apache.geronimo.naming.java.ComponentContextInterceptor.invoke
(ComponentContextInterc
eptor.java:56)
        at org.openejb.ConnectionTrackingInterceptor.invoke(
ConnectionTrackingInterceptor.java:81)
        at org.openejb.entity.EntityInstanceInterceptor.invoke(
EntityInstanceInterceptor.java:136)
        at org.openejb.entity.cmp.InTxCacheInterceptor.invoke(
InTxCacheInterceptor.java:90)
        at org.openejb.transaction.ContainerPolicy$TxRequired.invoke(
ContainerPolicy.java:140)
        at org.openejb.transaction.TransactionContextInterceptor.invoke
(TransactionContextIntercepto
r.java:80)
        at org.openejb.SystemExceptionInterceptor.invoke(
SystemExceptionInterceptor.java:82)
        at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java
:238)
        at org.openejb.server.ejbd.EjbRequestHandler.invoke(
EjbRequestHandler.java:297)
        at org.openejb.server.ejbd.EjbRequestHandler.doEjbHome_FIND(
EjbRequestHandler.java:394)
        at org.openejb.server.ejbd.EjbRequestHandler.processRequest(
EjbRequestHandler.java:209)
        at org.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:150)
        at org.openejb.server.ejbd.EjbServer.service(EjbServer.java:87)
        at
org.openejb.server.ejbd.EjbServer$$FastClassByCGLIB$$d379d2ff.invoke
(<generated>)
        at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
        at org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(
FastMethodInvoker.java:38)
        at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(
GBeanOperation.java:118)
        at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(
GBeanInstance.java:800)
        at org.apache.geronimo.gbean.runtime.RawInvoker.invoke(
RawInvoker.java:57)
        at org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(
RawOperationInvoker.java:36)
        at org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept
(ProxyMethodInterceptor.
java:96)
        at org.activeio.xnet.ServerService$$EnhancerByCGLIB$$e80ad14.service
(<generated>)
        at org.activeio.xnet.ServicePool$2.run(ServicePool.java:67)
        at org.activeio.xnet.ServicePool$3.run(ServicePool.java:90)
        at
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(
ThreadPool.java:138)
        at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown
Source)
        at java.lang.Thread.run(Unknown Source)
setEntityContext called
ejbActivate() called.
ejbLoad() called.

ejb-jar.xml

<?xml version="1.0"?>

<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
         version="2.1"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">

  <display-name>Product</display-name>

  <enterprise-beans>
    <entity>
      <ejb-name>Product</ejb-name>
      <home>examples.cmp.ProductHome</home>
      <remote>examples.cmp.Product</remote>
      <ejb-class>examples.cmp.ProductBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>examples.cmp.ProductPK</prim-key-class>

      <reentrant>false</reentrant>

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>PRODUCTS</abstract-schema-name>

      <cmp-field>
        <field-name>productID</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>description</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>basePrice</field-name>
      </cmp-field>


 <!--     <query>
        <query-method>
          <method-name>findByPrimaryKey</method-name>
          <method-params>
            <method-param>examples.cmp.ProductPK</method-param>
          </method-params>
        </query-method>
        <ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.productID= ?1
        </ejb-ql>
      </query> -->

      <query>
        <query-method>
          <method-name>findByName</method-name>
          <method-params>
            <method-param>java.lang.String</method-param>
          </method-params>
        </query-method>
        <ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.name = ?1
        </ejb-ql>
      </query>

      <query>
        <query-method>
          <method-name>findByDescription</method-name>
          <method-params>
            <method-param>java.lang.String</method-param>
          </method-params>
        </query-method>
        <ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.description = ?1
        </ejb-ql>
      </query>

      <query>
        <query-method>
          <method-name>findByBasePrice</method-name>
          <method-params>
            <method-param>double</method-param>
          </method-params>
        </query-method>
        <ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.basePrice= ?1</ejb-ql>
      </query>

      <query>
        <query-method>
          <method-name>findExpensiveProducts</method-name>
          <method-params>
            <method-param>double</method-param>
          </method-params>
        </query-method>
        <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.basePrice > ?1]]></ejb-ql>
      </query>

      <query>
        <query-method>
          <method-name>findCheapProducts</method-name>
          <method-params>
            <method-param>double</method-param>
          </method-params>
        </query-method>
        <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.basePrice < ?1]]></ejb-ql>
      </query>

      <query>
        <query-method>
          <method-name>findAllProducts</method-name>
          <method-params>
          </method-params>
        </query-method>
        <ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE
p.productIDIS NOT NULL</ejb-ql>
      </query>

    </entity>
  </enterprise-beans>

  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>Product</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>*</method-name>
      </method>
      <method>
        <ejb-name>Product</ejb-name>
        <method-intf>Home</method-intf>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>

</ejb-jar>

openejb-jar.xml

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

<openejb-jar
    xmlns="http://www.openejb.org/xml/ns/openejb-jar"
    xmlns:naming="http://geronimo.apache.org/xml/ns/naming"
    xmlns:security="http://geronimo.apache.org/xml/ns/security"
    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment"
    configId="ProductEJB"
    parentId="org/apache/geronimo/SystemDatabase">
<cmp-connection-factory>
     <resource-link>SystemDatasource</resource-link>
     <!-- <name>SystemDatasource</name> -->
</cmp-connection-factory>
<enterprise-beans>
    <entity>
        <ejb-name>Product</ejb-name>
        <jndi-name>ProductRemote</jndi-name>
        <local-jndi-name>ProductLocal</local-jndi-name>
        <table-name>PRODUCTS</table-name>
    <cmp-field-mapping>
        <cmp-field-name>productID</cmp-field-name>
        <table-column>PRODUCTID</table-column>
    </cmp-field-mapping>
    <cmp-field-mapping>
        <cmp-field-name>name</cmp-field-name>
        <table-column>NAME</table-column>
        </cmp-field-mapping>
    <cmp-field-mapping>
        <cmp-field-name>basePrice</cmp-field-name>
        <table-column>BASEPRICE</table-column>
        </cmp-field-mapping>
    <cmp-field-mapping>
        <cmp-field-name>description</cmp-field-name>
        <table-column>DESCRIPTION</table-column>
        </cmp-field-mapping>

    </entity>
</enterprise-beans>
</openejb-jar>

While i was debugging I saw a method
public IdentityTransform getPrimaryKeyTransform(Entity entity) in the class
IdentityDefinerBuilder. Here based on size of pkFields the SimplePKTransform
or CompoundPKTransform class is selected.
In the case of a custom class with 1 field also the SimplePKTransform is
selected.
Is this how it should behave? Could you give a general idea of how the
primary key values are taken from the Custom classes in OpenEJB?

Thanks
Manu







On 12/11/05, Gianny Damour < gianny.damour@optusnet.com.au> wrote:
>
> Hi Manu,
>
> This method is always supposed to get a String value.
>
> When a custom primary key is used, its type must be declared in the
> ejb-jar.xml DD via the prim-key-class element. Also, the primkey-field
> elements in both the ejb-jar.xml DD and openejb-jar.xml DD must not be
> set; these elements should be used only whne the CMP has a simple
> primary key. Could you please confirm that none of these elements have
> been set?
>
> Thanks,
> Gianny
>
> Manu George wrote:
>
> > Hi,
> >        I am facing a problem with some CMP EJBs with custom PrimaryKey
> > Classes. I am getting the EJBs deployed but during invoking of the
> > findbyprimarykey method I am getting a TransactionRolledBack
> > Exception. On investigating the cause of this I found that it was due
> > to  a ClassCastException that was ocurring in TranQL. In the class
> > org.tranql.sql.jdbc.binding.StringBinding
> > there is a method setValue. Here during execution the value parameter
> > contains the custom primary key class cast as Object. In the setString
> > method it gives a ClassCastException. Shouldn't this be a
> > value.toString() here? or is this method always supposed to get just a
> > string value?
> >
> >   public void setValue(PreparedStatement ps, Object value) throws
> > SQLException {
> >         ps.setString(index, (String) value);
> >     }
> >
> > Is there any specific property we need to put in openejb-jar.xml when
> > we use complex PrimaryKey classes over and above the entries in
> > ejb-jar.xml ?
> > Also for the <primkey-field> value in the openejb-jar.xml what do we
> > put if we have a complex primary key consisting of 2 fields?
> >
> > Thanks
> > Manu
> >
>
>
>
>

Mime
View raw message