• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

EntityManager.getReference method

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Promod
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic