geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dale de los Reyes" <>
Subject Request for CMP using Compound Key example
Date Mon, 06 Mar 2006 21:18:08 GMT

If anyone knows an example CMP entity bean that uses a compound/primary key 
class, please point me in the right direction. Or if someone knows what I'm 
missing. I would appreciate the help.

Using Geronimo with Tomcat 1.0 and Derby bundled in same package:

I created a simple entity bean with the following methods in the home class:
(Note: full syntax omiited for brevity)
someBean create(SomePrimaryKey key)
someBean findByPrimaryKey(SomePrimaryKey key)
Collection findByAll()

public final class SomePrimaryKey
   public Integer id;
   public String desc;

   SomePrimaryKey() {}

   public boolean equals(Object other) {
      if (other instanceof SomePrimaryKey) {
         return (id.equals(((SomePrimaryKey)other).id));

   public int hashCode()
      return id.hashCode();
   } // end hashCode

I know the above isn't using a compound key "per se", but GERONIMO-1361 
regarding compound keys with only 1 key is now closed, and should be working 
in Geronimo 1.0.

Anyway, I'm able to use this key class with BMP. However, when I switch the 
implementation to CMP, only the "create" and "findByAll" methods work. The 
"findByPrimaryKey" is unable to locate an existing entry in the database and 
instead returns an "ObjectNotFoundException".

When I convert the CMP to use a simple primary key (i.e. Integer 
primaryKey), all the CMP home methods work.

The examples I've seen so far (Product Line example in Mastering EJB 2nd ed 
and the examples bundled in the Geronimo docs), do not specify any EJB-QL 
code in the descriptors for the "findByPrimaryKey" method.

Here's a portion of my ejb-jar.xml descriptor

         <!-- <prim-key-class>java.lang.Integer</prim-key-class> -->



         <!-- omitted when using compound key -->
         <!-- <primkey-field>id</primkey-field> -->

            <description>DataSource for MachineShop Database</description>

         <!-- No query tag needed for findByPrimaryKey? -->


            <![CDATA[select object(b) from SomeCMP as b]]>

Here's a portion of my openejb-jar.xml





Again, any help is most appreciated.


View raw message