• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finder method returns collection ...

 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having a finder method called, findByFirstName() in the home interface which returns collection of home interfaces. Method definition in the componet is as follows,

public interface CustomerHome extends javax.ejb.EJBHome{
...............

public java.util.Collection.findByLastNae(.......) throws RemoteException, FinderException
...............
}

If the entity bean client wants to obtain and use remote home interface type objects from the collection returned by the findByFirstName(...) method, What the client should do?
Assume 'customer' object refers to the CustomerHome interface.

Ans :- (CustomerHome)customer.findByLastName(...) --------- Line 1

Till this every thing is fine. Now my concern is, finder method returns the collection of the objects, if the clinet calls the method at line 1, Which object from the collection he will get ( Mean, collection might have ten objects, which of the ten client will get)

Thanks in Advance,
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, I'm not completely sure that I'm understanding the question, so my apologies if I have it wrong...

I'll explain what I think is the issue;

1) There are two kinds of finders--single entity and multiple entity
2) Single entity finders return the actual component interface of a single entity
3) Multiple entity finders return a Collection of component interfaces

The client knows the return type of the finder (either a Component interface type or a Collection), so when the client calls a multiple entity finder, the client assigns the returned value to a Collection reference. Then it is up to the client to iterate through the Collection of component interfaces and do whatever it is the client wants to do...

If a findByLastName() method returns a Collection of all entities matching the last name, then the client gets a Collection of ALL the component interfaces for those entities, and the client now can access the individual Collection elements and cast/assign them to the actual component interface type.

(For remote interfaces, multiple entity finders should be used with great caution, because do you REALLY want the overhead of getting all those stubs over to the client? This is a good use for perhaps a Home business method that simply returns a String with perhaps the names and primary keys for the matching entities, and then let the client make a new request for the stubs of just the specific entities the client wants...)

Again, my apologies if I've explained the wrong thing

cheers,
Kathy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic