Meaningless Drivel is fun!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EntityManager.getReference method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EntityManager.getReference method" Watch "EntityManager.getReference method" New topic
Author

EntityManager.getReference method

Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
According to the JavaDoc

EntityManagergetReference(Class<T> entityClass,Object primaryKey) wrote:
If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed. (The persistence provider runtime is permitted to throw EntityNotFoundException when getReference(java.lang.Class, java.lang.Object) is called.)


I confused with this. It says that the given exception is thrown when the instance state is first accessed. But within brackets it says that exception is thrown when the method is invoked. What a conflicting idea is this? When will the exception actually throwable?
Promod kumar
Ranch Hand

Joined: Jun 26, 2006
Posts: 90
I just tried this in a SLSB's addItem method. There is no Seller on the DB with id "testing". Interestingly it failed with EntityNotFoundException on the second line which is when we are accesssing the state of the instance.



Also I looked at the javadoc for EntityNotFoundException and it talked about getReference and refresh being the methods that throw this exception. You can pretty much ignore the text in the bracket, (The persistence provider runtime is permitted to throw EntityNotFoundException when getReference(java.lang.Class, java.lang.Object) is called.)


Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Thanks Promod
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EntityManager.getReference method