• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

findXXX methods in EJB 2.x

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe it should be empty collection
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 4274
34
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just verified this and when we return a Collection or an Enumeration, we do not get a FinderException.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When it is not throwing a FinderException, then why do I have to explicitly say throws FinderException in my component interfaces?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we are returning a collection for finder methods,
can we use list or set as a return type for finder methods??
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"banti_mca2004", please check your private messages.
[ October 06, 2008: Message edited by: Paul Sturrock ]
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic