Hai,
javax.ejb.ObjectNotFoundException is a subclass of
javax.ejb.FinderException that is thrown from the single finder/select method (the ones that return comp interface rather than a collection) when an object does not exist. As you pointed out it is a standard application exception.
Eg, client calls
findByPrimaryKey( Object pk ) but there is no record in the underlying db with the given pk - Container throws
ObjectNotFoundException. It means eb instance cannot represent an entity (record in db) that has given pk.
[javax.ejb.NoSuchEntityException] is thrown by the bean code when the entity (record in db) has been removed from the underlying persistence store (db) but the entity bean is still associated with it.
Eg, client calls
findByPrimaryKey( Object pk ) and gets back EJBObject (it means that there is a record associated with the given pk). Client calls a business method on this EJBObject - on the container side bean instance is pulled out from the pool, loaded with the entity (record in db) data and invoked a business method that returns a method's result to the client. All OK till now.
Client code does something else for a while and then decides to call another business method on the same EJBObject (same entity bean). However, between first business method invocation and the second one the actual entity (record in db) has been removed from the persistence store by external party (eg, dba logged into the database and deleted a record). Our entity bean is still associated with this entity at the time of the second business method invocation. Container tries to refresh (ejbLoad()) the entity bean with the entity data -> no entity in the persistence store ->
NoSuchEntityException.
Hope it helps
