• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finder Method Return Type

 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I am a little lost, I need your guidance.
My understanding is that in an entity bean, the finder methods return the remote interface type or a collection of these. Now , when I write my finder methods, I am trying to get Resultset, by executing some query, and it is this resultset that I am interested in, which in my view is not really the remote interface type,or a collection of these since in the query I specify maybe only a few interesting fields. So, when I get the result set from my query, how do I get a bean out of it. For example, lets say I have a data base with a table called pets. I write a method called <b>ejbFindAllPets</b> and in it I run the query <b>SELECT * FROM PETS</b>. How do I pass this result set to my remote interface so I can get a listing of the Pets?
I hope my question is clear.
Herbert.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Herbert,
From your description, I assume you are using a BMP entity bean (as opposed to a CMP) entity bean. Your entity bean should have a primary key. The "ejbFindAllPets()" method needs to return a "Collection" of primary keys. If you have defined a separate "primary key" (java) class, then in method "ejbFindAllPets()", create a "Collection" of these objects from the data returned by your SQL query (the contents of your "ResultSet"). If your primary key is merely a single attribute of your entity bean, then create a "Collection" of that attribute only. If that attribute is a primitive (like "int", for example), then make a "Collection" of "wrapper" objects -- in other words "Integer", instead of "int".
Of-course, if you haven't already done so, then reading through the multitude of available resources is recommended. Allow me to suggest the following (for starters):
  • "Mastering EJB" -- book as PDF file from http://www.theserverside.com
  • J2EE Tutorial
  • EJB Specification


  • Good Luck,
    Avi.
    [ March 29, 2004: Message edited by: Avi Abrami ]
     
    Seetesh Hindlekar
    Ranch Hand
    Posts: 244
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Herbert,
    There is no concept of returning a ResultSet in EJB. Whatever finder methods u write should return a Collection when the records are more than one. Even ur client should have the finder method written to get a Collection object from the finder method
    Collection colbig = hhome.findBigAccounts(1500.0);
    if(colbig.isEmpty())
    { out.println("No accounts were found!");
    }
    Iterator itbig = colbig.iterator();
    while (itbig.hasNext())
    {
    Account bigAccount = (Account) PortableRemoteObject.narrow
    (itbig.next(), Account.class);
    String PK = bigAccount.getPrimaryKey();
    String Balance = bigAccount.balance();
    }
    HTH,
    Seetesh
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!