The orion finders are wonderfully straightforward in this regard (joins 
across entities), but you have to be a bit careful.  Here's a quick example.

An Employee bean has a reference to Office.  The Office bean has an int 
numStaff attribute.  I want to define a finder method that shows me all 
employees who work in offices with more than X many staff.  So, in 
EmployeeHome.java I define:

   Collection findByMinimumStaff( int numStaff ) throws FinderException, 
RemoteException;

In the orion-ejb-jar.xml for the Office bean's jar:

<entity-deployment name="Office" table="Office">
   <!-- hard code table and field names because we will be using them in a 
finder elsewhere -->
   <cmp-field-mapping name="id" persistence-name="id" />
   <cmp-field-mapping name="numStaff" persistence-name="numStaff" />
</entity-deployment>

In the orion-ejb-jar.xml for the Employee bean's jar:

<entity-deployment name="Employee" table="Employee>
   <!-- again, hard code the fields that appear in the finders -->
   <cmp-field-mapping name="officeId" persistence-name="officeId" />

   <!-- now we can write our finder, which is a join across Employee and 
Office -->
   <!-- note: partial="false" means we are supplying the whole query, not 
just the WHERE clause -->

   <finder-method partial="false" query="SELECT e.* FROM Employee e, Office o
                                         WHERE o.numStaff > $1 AND 
e.officeId = o.id">
     <method>
       <ejb-name>Employee</ejb-name>
       <method-name>findByMinimumStaff</method-name>
       <method-params>
         <method-param>int</method-param>
       </method-params>
     </method>
   </finder-method>
</entity-deployment>


Disclaimer: this is just off the top of my head - I haven't written an 
Employee and Office bean to test this, but it should give you an idea of 
the approach to take.  Obviously you can join across more than two tables, 
have UNION ALL statements, etc.  Just so long as you return no more or less 
than the fields for Employee.* so that orion gets back the columns it expects.

Hope that helps,
Dan/tastapod


At 13:38 06/04/2001 +1000, you wrote:
>Hello,
>
>
>Does anyone on this list know if an EB using an Entity Reference as an
>attribute, can have a finder method
>search on that attribute? If so can you search on attributes of the
>afore mentioned entity reference?
>
>
>
>--
>
>Adam Cassar
>Technical Development Manager
>___________________________________________
>NetRegistry http://www.netregistry.au.com
>Tel: +61 2 9641 8609 | Fax: +61 2 9699 6088
>PO Box 270 Broadway NSW 2007 Australia

--
Dan North
VP Development  -  Cadrion Software Ltd  -  +44 (0)20 7440 9550

CONFIDENTIALITY
This e-mail and any attachments are confidential
and may also be privileged. If you are not the named recipient,
please notify the sender immediately and do not disclose the
contents to another person, use it for any purpose, or store
or copy the information in any medium


Reply via email to