• Post Reply Bookmark Topic Watch Topic
  • New Topic

findByPrimaryKey : ObjectNotFoundException

 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a doubt regarding the behavior of findByPrimaryKey () method.
It throws an ObjectNotFoundException if no records in the database match the id argument. This is exception should always be thrown by single-entity find methods if no entity is found. However, multi-entity find methods(returning a collection of remote/local interfaces ) do not throw ObjectNotFoundExceptions if no entities are found. Why this is so? Why the behavior differs on the return type of the findby method?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're looking for a particular entity and it is not found, you're most often expecting it to be found, thus, the exception.
If you're looking for "any" entities matching a given criteria, you're most often not expecting any particular number of matches, thus, no exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!