Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FinderException / ObjectNotFoundException

 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what will be the answer of the following question.

If I call findByPrimaryKey(23) on a Home and no object with pk 23 exists,
Which of the following statement is true?

1) I'll get a FinderException.
2) I'll get a ObjectNotFoundException.
3) I can't tell for sure.
4) None of the above.

Now, According to HFEJB, I can't rely on the most specific exception. In that case the answer should be 3. But what's the point of having ObjectNotFoundException if I don't get it surely?
What do u pple think?
regards,
Sajid
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the question is about "no object with pk 23 exists" - I think container would get ons instance ready to act as "object with pk 23" as per diagram on page 348 of HFEJB (by pulling one instance out of pool, calling ejbActivate, doing select from DB, then populating EB and then calling ejbLoad).

Only in the scenario when "no entity with pk 23 exists - in the underlying persistent store" the container should throw ObjectNotFoundException. And the specification says that the container *should* throw ObjectNotFoundException, means this more specific exception is recommended, but not mandated.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!