What you have here is a simple one-to-many relation (department to employee).
There are two ways you could go with this. Either you could have a find method
in Employee that finds Employees by their Department ID...that way you would
look up a Department, get its ID, pass it to Employee, and get a bunch of
Employyes back.
Or (and I don't know if jBoss supports this yet), EJB allows you to have entity
beans store referenced to other entity beans based on some relation (in this
case the relation of Department's primary key to a field in Employee). Using
container-managed persistence, the server will automatically load all the
employees bound to the department into an array in the department bean. Having
never done this, I don't know the exact mechanics, but the O'Reilley book
Enterprise Java Beans describes how to do this.
-Charles
Wes Mckean wrote:
> This doesn't really have anything to do with jBoss as an application server,
> but is more a philisophical question involving EJBs.
>
> What is the basic architecture for handling objects which are owned by other
> objects? Given the following example:
>
> I have a department, and that department "owns" the employees to which it
> has been assigned. Therefore, I create my standard entity bean for the
> department.
>
> Entity Bean: Department
>
> I look up my home object, create my department EJB, it loads and everything
> is fine. I now want to get a list of all the employees in my department. I
> throw in a second entity bean.
>
> Entity Bean: Employee
>
> What is the best recommended method for accessing the employees?
>
> Do I say sometyhing like: Enumeration employeeList =
> Department.getEmployees(); In this case, is it OK to have one EJB look up
> the home object on another and return the Enumeration returned by the find
> method?
>
> Or do I do something like:
>
> Look up the Employee home object. Execute a findByDeparmentID method?
>
> Having not done this before, I value your opinion.
>
> Thx!
>
> Wes
>
> --------------------------------------------
> Wes McKean
> Director Platform Management
> U.S. South Communications, Inc.
> 770-240-6114
> [EMAIL PROTECTED]
>
> --
> --------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Problems?: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]