File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes findXXX methods in EJB 2.x Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "findXXX methods in EJB 2.x" Watch "findXXX methods in EJB 2.x" New topic
Author

findXXX methods in EJB 2.x

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

Guys,

I have a method that has the following signature,

public Collection findByUserId() throws FinderException, now what will my Collection be if there are no users found? Will it throw a FinderException or will it not? If it is not throwing a FinderException, what value will my collection have? Will it be null or an empty Collection?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Kalyan Anand
Ranch Hand

Joined: Feb 07, 2007
Posts: 194
I believe it should be empty collection
Steffen Neustadt
Greenhorn

Joined: Sep 30, 2008
Posts: 11
Originally posted by Jothi Shankar Kumar Sankararaj:
Guys,

I have a method that has the following signature,

public Collection findByUserId() throws FinderException, now what will my Collection be if there are no users found? Will it throw a FinderException or will it not?

IMHO
if a function shall trigger an exception it has to build an exception-oject and initiate the handling of the exception. therefore use the key-word "throw"


If it is not throwing a FinderException, what value will my collection have? Will it be null or an empty Collection?

you define it in the find-method by initialisating the return value...
..as I would say...
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

Originally posted by Steffen Neustadt:

you define it in the find-method by initialisating the return value...
..as I would say...


I really did not get you...
Steffen Neustadt
Greenhorn

Joined: Sep 30, 2008
Posts: 11
Originally posted by Jothi Shankar Kumar Sankararaj:


I really did not get you...


in my opinion you habe a method findxy() with return value of typ collection, right?
So you have to return a value of this typ, f.i.
public collection findxy(){
//what ever you do, somewhere you have to get a value c
// c=new Collection(); c.add(xy);...
//c=what you have found;
return c;

}

so if nothing found c=empty, or you gave it an other value in your method...
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

Let me put my question in this way,

I have in my HomeInterface the following declaration,



And in my caller, I have the following definition,



Now in my caller above, what if my Collection is empty? Will it throw a FinderException?
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

These are great questions but why not try it out? Since you have the code all ready it should be easy enough to setup and try yourself.


My Blog: Down Home Country Coding with Scott Selikoff
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

I just verified this and when we return a Collection or an Enumeration, we do not get a FinderException.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

When it is not throwing a FinderException, then why do I have to explicitly say throws FinderException in my component interfaces?
raj
Greenhorn

Joined: Feb 09, 2007
Posts: 8
hi,
"findbyprimarkey" is a finder method,if this method returns a collection of keys(against a single key) then we will get "finderexception"
that's why we should throw finderexceptions for finder methods.
for other finder methods, we will return collection.if no records are found to return, then the method will return a empty collection object(not null).
raj
Greenhorn

Joined: Feb 09, 2007
Posts: 8
we are returning a collection for finder methods,
can we use list or set as a return type for finder methods??
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"banti_mca2004", please check your private messages.
[ October 06, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9426
    
    2

Originally posted by rajeshmanepalli rajeshmanepalli:
hi,
"findbyprimarkey" is a finder method,if this method returns a collection of keys(against a single key) then we will get "finderexception"
that's why we should throw finderexceptions for finder methods.
for other finder methods, we will return collection.if no records are found to return, then the method will return a empty collection object(not null).


Your post seems contradictory to what I have tested. Please be clear and format your sentences. I find it hard to follow.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: findXXX methods in EJB 2.x