Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

objectnotfoundexception

 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 548 of HF, has the following descrciption of ObjectNotFoundException
The container throws this to the client ONLY during single-entity finder methods, when there's no entity in the database matching the primary key parameter of the finder method.

This statement implies that the only finder method that returns a single-entity is one that takes a primary key parameter. Is this the case, or can a single-entity finder method take paramters that do not include the primary key?
Thanks a mill.
[ January 29, 2004: Message edited by: Keith Rosenfield ]
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- yeah, *any* single-object finder (including findByPrimaryKey()) can throw an ObjectNotFoundException. Remember, though, that the Container is also free to throw just the superclass FinderException. Whether the Container decides to throw the more specific subclass ObjectNotFoundException is optional, in the spec. But that's a minor point -- the purpose of ObjectNotFoundException (in fact, it's ONLY purpose) is to indicate that a single-object finder did not locate a single object that matches the query.
cheers,
Kathy
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clearing that up.
 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathy,
From your answer --

"But that's a minor point -- the purpose of ObjectNotFoundException (in fact, it's ONLY purpose) is to indicate that a single-object finder did not locate a single object that matches the query. "


What about the instance when a reference to a bean (any bean) exists on the client , but the bean instance has been removed and the client tries to invoke a method via the reference - ObjectNotFoundException is thrown isn't it ? This is a valid scenario too - so the "ONLY purpose" might not be technically correct
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Akasmat,
A NoSuchObjectException would be thrown in your scenario NOT a ObjectNotFoundException. The NoSuchObjectException is thrown when an attempt is made to call a method on an EJBObject that no longer exists.
Hope this helps.
 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathy,
From your answer --

"But that's a minor point -- the purpose of ObjectNotFoundException (in fact, it's ONLY purpose) is to indicate that a single-object finder did not locate a single object that matches the query. "


What about the instance when a reference to a bean (any bean) exists on the client , but the bean instance has been removed and the client tries to invoke a method via the reference - ObjectNotFoundException is thrown isn't it ? This is a valid scenario too - so the "ONLY purpose" might not be technically correct
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic