• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Finder method returns collection ...

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic