• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Weired Problem

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic