• Post Reply Bookmark Topic Watch Topic
  • New Topic

Weired Problem

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
I have a weired problem.
I have the following finder method in a local home interface:
Collection findByCityName(String city) throws FinderException;
the ejb-ql for the previous finder is:
SELECT OBJECT(T) FROM Team AS T WHERE T.city = ?1
the previous method is used by a session facade as the following :

now, when using this method from a client and supplied a correct value (a value that exists in a database), I got a right answer, but when supplied a value that does not exists in the database, I got nothing.
not an exception in the console, not an exception in JBoss console and not in the log file !
any ideas ??
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not receive an exception in this case (no beans match query) -- you simply get an empty collection.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why I don't recieve a FinderException ? I provided a value that doesn't exists.
when FinderException will be thrown ?
thanks for help.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following is from a client :

I don't have teams within chicago city, so teams should be null.
but when running the client, I don't get the message :
"There is no teams in chicago"
this mean it is not null ! (it should be, I don't have teams in chicago), even the else statement is not executed !
why ?
 
Brian Tinnel
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The returned collection will be empty (size() == 0) when nothing is found.

If you really want a null if the collection is empty you could just change you session bean code from



to

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks lot.
in which situations we get FinderException ?
[ September 30, 2004: Message edited by: John Todd ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Todd:
[I]n which situations we get FinderException ?

From the EJB 2.0 Specification:
  • 10.5.6.1 - ObjectNotFoundException (a subclass of FinderException) should be thrown if multiple results are found for a finder method that is declared to return a single object.
  • 10.5.7.1 - The same applies to select methods.
  • 10.5.8.4 - "Only single-object finder or select methods should throw ObjectNotFoundException. Multi-object finder or select methods should return an empty collection as an indication that no matching objects were found."

  • The reasoning for this is that for the query "find all users named Bob," you don't normally enforce there to be at least one matching user. This is generally true for queries returning multiple results: you are looking for objects. If you don't find any, no big deal. When you're looking for a specific object, however, it should be an error if it's not found since you were expecting it to be there.

    Anyway, you are free to set up your API any way you like. If you think looking for Bob and not finding anyone with that name is a serious error, throw an application exception of your own, BobNotFoundException for example (or perhaps TeamNotFoundException in this case).
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!