3 Replies Latest reply on Jul 19, 2002 6:18 PM by Dain Sundstrom

    JBoss 3.0.0 - CMR and composite primary key

    Peter Coppens Newbie

      A while back, when the jboss forum was down for a couple of days, I posted the message below at jboss-user@lists.sourceforge.net and got a fast answer saying I was bumping into a known bug.

      I just tested the same with 3.0.1RC1 and the issue is still there, but I can't seem to find a bug (assuming I am looking in the right place).

      So my question is, whether the behaviour below is indeed a known bug and if someone knows the bug#, so I can to track it waiting for a solution.

      To be honest, As this is such a 'common' thing to do (I would think), it surpises me that this would not work (perhaps I am just doing something wrong).

      Here is the original post and reply

      Thanks for any help.

      ....

      Known bug.

      On tor, 2002-06-06 at 23:24, Peter Coppens wrote:
      > Hi,
      >
      > I wonder whether anyone has experienced problems with one-to-many CMR, where
      > the many bean has a composite primary key.
      >
      > It is a 'typical' vendor-vendoritems relation. Primary key for the vendor is
      > email, primary key for the vendoritem is (email,id).
      >
      > The code is below and it throws an exception when accessing any of the
      > vendoritems attributes.
      >
      > The 'strange' thing is that when there is only one vendoritem for a given
      > vendor it works fine. When there is more than one, I get the exception as
      > listed after the code.
      > When I make the primary key in the vendoritem just the id, it works fine as
      > well.
      >
      > Tracing what is returned from the RDBMS looks ok to me.
      >
      > Thanks,
      >
      > Peter
      >
      >
      > ------------
      > Code extract
      > ------------
      > public LolVendorItemInfo[] getVendorItems ( String email )
      > {
      > try
      > {
      > ArrayList lolVendorItemList = new ArrayList ( 50 );
      > LolVendor lolVendor = this.lolVendorHome.findByPrimaryKey ( email );
      > Collection lolVendorItemColl = lolVendor.getItems ( );
      > Iterator lolVendorItemIterator = lolVendorItemColl.iterator ( );
      > while ( lolVendorItemIterator.hasNext ( ) )
      > {
      > try
      > {
      > LolVendorItem lolVendorItem = ( LolVendorItem )
      > lolVendorItemIterator.next ( );
      > LolVendorItemInfo lolVendorItemInfo = new LolVendorItemInfo (
      > lolVendor.getEmail ( ) );
      > lolVendorItemInfo.setItemId ( lolVendorItem.getId ( ) ); /*
      > Exception is thrown here */
      > lolVendorItemInfo.setItemDescription (
      > lolVendorItem.getDescription ( ) );
      > lolVendorItemInfo.setItemPrice ( lolVendorItem.getPrice ( ) );
      > lolVendorItemList.add ( lolVendorItemInfo );
      > }
      > catch ( Exception e )
      > {
      > e.printStackTrace ( System.out );
      > }
      > }
      > return ( LolVendorItemInfo[] ) lolVendorItemList.toArray ( new
      > LolVendorItemInfo [ lolVendorItemList.size ( ) ] );
      > }
      > catch ( FinderException e )
      > {
      > throw new EJBException ( "Unable to get list of vendor items ", e );
      > }
      > }
      >
      > -------------------------
      > Small part of stack trace
      > -------------------------
      > 2002-06-06 12:36:37,992 DEBUG
      > [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.LolVendorItemBean]
      > Executing SQL: SELECT Email, Id,Description, Price FROM lol_vendoritem WHERE
      > (Email=? AND Id=?) OR (Email=? AND Id=?) OR (Email=? AND Id=?) OR (Email=?
      > AND Id=?) OR (Email=? AND Id=?) OR (Email=? AND Id=?) OR (Email=? AND Id=?)
      > OR (Email=? AND Id=?) OR (Email=? AND Id=?) OR (Email=? AND Id=?)
      > 2002-06-06 12:36:38,123 ERROR [org.jboss.ejb.plugins.LogInterceptor]
      > TransactionRolledbackException, causedBy:
      > javax.ejb.NoSuchEntityException: Entity not found:
      > primaryKey=com.ddtek.lol.LolVendorItemPK@f92a41
      > at
      > org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityC
      > ommand.java:165)
      > ....
      >
      > -----------
      > Part of ejb-jar.xml
      > -----------
      >
      >
      > <display-name>LolVendorBean</display-name>
      > <ejb-name>LolVendorBean</ejb-name>
      >
      > <local-home>com.ddtek.lol.LolVendorHome</local-home>
      > com.ddtek.lol.LolVendor
      > <ejb-class>com.ddtek.lol.LolVendorBean</ejb-class>
      >
      > <persistence-type>Container</persistence-type>
      > <prim-key-class>java.lang.String</prim-key-class>
      >
      > True
      > <cmp-version>2.x</cmp-version>
      >
      > <abstract-schema-name>LolVendorBean</abstract-schema-name>
      >
      > <cmp-field>
      > no description
      > <field-name>Email</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>Name</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>Phone</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>Fax</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>StreetAndNr</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>PostalCode</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>City</field-name>
      > </cmp-field>
      >
      > <primkey-field>Email</primkey-field>
      >
      > <security-identity>
      >
      > <use-caller-identity></use-caller-identity>
      > </security-identity>
      >
      >
      >
      > <query-method>
      > <method-name>findAll</method-name>
      > <method-params />
      > </query-method>
      > <ejb-ql>select Object(o) from LolVendorBean as o</ejb-ql>
      >
      >
      >
      >
      >
      >
      > <display-name>LolVendorItemBean</display-name>
      > <ejb-name>LolVendorItemBean</ejb-name>
      >
      > <local-home>com.ddtek.lol.LolVendorItemHome</local-home>
      > com.ddtek.lol.LolVendorItem
      > <ejb-class>com.ddtek.lol.LolVendorItemBean</ejb-class>
      >
      > <persistence-type>Container</persistence-type>
      >
      > True
      > <cmp-version>2.x</cmp-version>
      >
      > <abstract-schema-name>LolVendorItemBean</abstract-schema-name>
      >
      > <cmp-field>
      > no description
      > <field-name>Email</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>Id</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>Description</field-name>
      > </cmp-field>
      > <cmp-field>
      > no description
      > <field-name>Price</field-name>
      > </cmp-field>
      >
      > <prim-key-class>com.ddtek.lol.LolVendorItemPK</prim-key-class>
      >
      > <security-identity>
      >
      > <use-caller-identity></use-caller-identity>
      > </security-identity>
      >
      >
      >
      > <query-method>
      > <method-name>findAll</method-name>
      > <method-params />
      > </query-method>
      > <ejb-ql>select Object(o) from LolVendorBean as o</ejb-ql>
      >
      >
      >
      > .....
      > <ejb-relation>
      > <ejb-relation-name>VendorSellsItems</ejb-relation-name>
      >
      > <ejb-relationship-role>
      >
      > <ejb-relationship-role-name>VendorSellsItems</ejb-relationship-role-name>
      > One
      > <relationship-role-source>
      > <ejb-name>LolVendorBean</ejb-name>
      > </relationship-role-source>
      > <cmr-field>
      > <cmr-field-name>Items</cmr-field-name>
      > <cmr-field-type>java.util.Collection</cmr-field-type>
      > </cmr-field>
      > </ejb-relationship-role>
      >
      > <ejb-relationship-role>
      >
      > <ejb-relationship-role-name>ItemIsSoldByVendor</ejb-relationship-role-name>
      > Many
      > <relationship-role-source>
      > <ejb-name>LolVendorItemBean</ejb-name>
      > </relationship-role-source>
      > <cmr-field>
      > <cmr-field-name>Vendor</cmr-field-name>
      > </cmr-field>
      > </ejb-relationship-role>
      >
      > </ejb-relation>
      >