My last shred of sanity is vapourizing as I type. I've spent several
fruitless days trying to work around Orion 1.4.7's inability to generate a
working finder method that takes an Entity reference as an argument. When I
finish composing this message I think I'll gibber under my desk for a while.
Help.

Among many others, I've got two Entity EJBs built: CatalogEJB and
CatalogEntryEJB. Both are CMP entities. CatalogEntryEJB has a working 1:1
CMR uni-directional relationship to CatalogEJB. I've defined the following
finder method in the home interface of CatalogEntryEJB so that a CatalogEJB
instance can find all the CatalogEntryEJB instances that 'belong' to it:

----------------
    Collection findByCatalog(Catalog catalog)
        throws EJBException, RemoteException, FinderException;
----------------

Once deployed, the descriptor entry for CatalogEntryEJB contains the
following:

----------------
   <finder-method query="">
    <!-- Generated SQL: "select CatalogEntryEJB.identity,
CatalogEntryEJB.catalogIdentity, CatalogEntryEJB.catalogLocale,
CatalogEntryEJB.label, CatalogEntryEJB.targetRoleIdentity,
CatalogEntryEJB.referenceidentity, CatalogEntryEJB.price,
CatalogEntryEJB.discountRate, CatalogEntryEJB.parentreferenceidentity,
CatalogEntryEJB.referenceTypeInt, CatalogEntryEJB.productCode,
CatalogEntryEJB.description, CatalogEntryEJB.extendedDescription,
CatalogEntryEJB.listIndex, CatalogEntryEJB.created, CatalogEntryEJB.creator,
CatalogEntryEJB.modified, CatalogEntryEJB.modifier from CatalogEntryEJB" -->
    <method>
     <ejb-name>CatalogEntryEJB</ejb-name>
     <method-name>findByAll</method-name>
     <method-params>
     </method-params>
    </method>
   </finder-method>
   <finder-method query="$catalog = $1">
    <!-- Generated SQL: "select CatalogEntryEJB.identity,
CatalogEntryEJB.catalogIdentity, CatalogEntryEJB.catalogLocale,
CatalogEntryEJB.label, CatalogEntryEJB.targetRoleIdentity,
CatalogEntryEJB.referenceidentity, CatalogEntryEJB.price,
CatalogEntryEJB.discountRate, CatalogEntryEJB.parentreferenceidentity,
CatalogEntryEJB.referenceTypeInt, CatalogEntryEJB.productCode,
CatalogEntryEJB.description, CatalogEntryEJB.extendedDescription,
CatalogEntryEJB.listIndex, CatalogEntryEJB.created, CatalogEntryEJB.creator,
CatalogEntryEJB.modified, CatalogEntryEJB.modifier from CatalogEntryEJB
where CatalogEntryEJB.catalogIdentity = ? and CatalogEntryEJB.catalogLocale
= ?" -->
    <method>
     <ejb-name>CatalogEntryEJB</ejb-name>
     <method-name>findByCatalog</method-name>
     <method-params>

<method-param>com.canlink.components.model.catalog.Catalog</method-param>
     </method-params>
    </method>
   </finder-method>
----------------

When called from a method in CatalogEJB, the findByAll method works fine,
returning all the CatalogEntryEJB instances in existence. However, the
findByCatalog method always returns an empty Collection, no matter what may
exist in the database. There is never any exception thown, it just always
returns an empty Collection. If I manually execute the generated SQL
statement, I do in fact get the appropriate results.

Investigating deeper, I've aimed Together Control Center's debugger at this
bit of the generated code for the CatalogEntryEJB Home's findByCatalog
method:

----------------
java.sql.PreparedStatement statement = connection.getCustomStatement("select
CatalogEntryEJB.identity, CatalogEntryEJB.catalogIdentity,
CatalogEntryEJB.catalogLocale, CatalogEntryEJB.label,
CatalogEntryEJB.targetRoleIdentity, CatalogEntryEJB.referenceidentity,
CatalogEntryEJB.price, CatalogEntryEJB.discountRate,
CatalogEntryEJB.parentreferenceidentity, CatalogEntryEJB.referenceTypeInt,
CatalogEntryEJB.productCode, CatalogEntryEJB.description,
CatalogEntryEJB.extendedDescription, CatalogEntryEJB.listIndex,
CatalogEntryEJB.created, CatalogEntryEJB.creator, CatalogEntryEJB.modified,
CatalogEntryEJB.modifier from CatalogEntryEJB where
CatalogEntryEJB.catalogIdentity = ? and CatalogEntryEJB.catalogLocale = ?");
try {
    com.canlink.components.base.LocalizedEntityPK primaryKey398 =
    argument0 == null ? null :
        ((com.canlink.components.base.LocalizedEntityPK)
argument0.getPrimaryKey());
    {
        if (primaryKey398 == null) {
            if (((java.util.Locale) null) == null) statement.setNull(1,
java.sql.Types.VARCHAR);
            else
                statement.setString(1,

com.evermind.util.ObjectUtils.toString(((java.util.Locale) null)));
            if (((java.lang.String) null) == null) statement.setNull(2,
java.sql.Types.VARCHAR);
            else
                statement.setString(2, ((java.lang.String) null));
        }
        else {
            if (primaryKey398.locale == null) statement.setNull(1,
java.sql.Types.VARCHAR);
            else
                statement.setString(1,

com.evermind.util.ObjectUtils.toString(primaryKey398.locale));
            if (primaryKey398.identity == null) statement.setNull(2,
java.sql.Types.VARCHAR);
            else
                statement.setString(2, primaryKey398.identity);
        }
    }
}
finally {
}
java.sql.ResultSet set = statement.executeQuery();
while (set.next()) {
    ....
}
----------------

Although I can't inspect anything while debugging this code (presumably
because Orion compiles it without debugging info), I can step through it and
observe that primaryKey398 is not null, and that both appropriate
statement.setString() methods are being called. I can also observer that
much to my disappointment, the ResultSet never returns true from its next()
method since the contents of the while{} block at the end of this snippet is
never executed.

Interestingly, the generated code (below) for the findByAll method always
works: the ResultSet contains all the extant CatalogEntryEJB rows, and the
while{} block gets executed for each one.

----------------
java.sql.PreparedStatement statement = connection.getCustomStatement("select
CatalogEntryEJB.identity, CatalogEntryEJB.catalogIdentity,
CatalogEntryEJB.catalogLocale, CatalogEntryEJB.label,
CatalogEntryEJB.targetRoleIdentity, CatalogEntryEJB.referenceidentity,
CatalogEntryEJB.price, CatalogEntryEJB.discountRate,
CatalogEntryEJB.parentreferenceidentity, CatalogEntryEJB.referenceTypeInt,
CatalogEntryEJB.productCode, CatalogEntryEJB.description,
CatalogEntryEJB.extendedDescription, CatalogEntryEJB.listIndex,
CatalogEntryEJB.created, CatalogEntryEJB.creator, CatalogEntryEJB.modified,
CatalogEntryEJB.modifier from CatalogEntryEJB");
java.sql.ResultSet set = statement.executeQuery();
while (set.next()) {
...
}
----------------

Why on earth does the findByCatalog method never, ever, ever find anything?

I've tried to work around this by creating a finder that takes the primary
key fields of the CatalogEJB, but Orion refuses to accept a query that
refers to the PK fields of Catalog, insistently shrieking the following at
me:

----------------
Auto-deploying producer-ejb.jar (No previous deployment found)... Error
compiling file:/D:/orion/applications/phlox/producer-ejb.jar: Field  used in
finder query not found in bean, valid fields are: catalog, label,
targetRole, reference, price, discountRate, parentReference,
referenceTypeInt, productCode, description, extendedDescription, listIndex,
created, creator, modified, modifier at column 605 in query ' select
CatalogEntryEJB.identity, CatalogEntryEJB.catalogIdentity,
CatalogEntryEJB.catalogLocale, CatalogEntryEJB.label,
CatalogEntryEJB.targetRoleIdentity, CatalogEntryEJB.referenceidentity,
CatalogEntryEJB.price, CatalogEntryEJB.discountRate,
CatalogEntryEJB.parentreferenceidentity, CatalogEntryEJB.referenceTypeInt,
CatalogEntryEJB.productCode, CatalogEntryEJB.description,
CatalogEntryEJB.extendedDescription, CatalogEntryEJB.listIndex,
CatalogEntryEJB.created, CatalogEntryEJB.creator, CatalogEntryEJB.modified,
CatalogEntryEJB.modifier from CatalogEntryEJB where
CatalogEntryEJB.catalogIdentity = ? and CatalogEntryEJB.catalogLocale = ?'
----------------

The above deployment error occurs regardless of whether I include a full or
partial query definition in either the orion-ejb-jar.xml or in the Home
Interface class.

Without working finders, Orion's CMP EJB implementation is pretty much
useless. I've seen messages in the archive indicating the finders that take
Entity references as arguments do in fact work.What on earth am I doing
wrong here?

P. Pontbriand
Canlink Interactive Technologies, Inc.




Reply via email to