Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EntityManager.getReference method

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Promod
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic