I am new to hibernate. I am trying to implement a business rule where i need to check if a record exists in the database to continue different path based on the existance /not.
I am trying to ask if there is a light weight way to see if a record exists in database.
please point me to the documentation if there are some available.
Thanks for reading
当您知道主键值时,请查看EntityManager#find
( http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#find ( java.lang.Class,java .lang.Object) 。
More lightweight solution is use:
getReference
<T> T getReference(java.lang.Class<T> entityClass,
java.lang.Object primaryKey)
Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, the EntityNotFoundException is thrown when the instance state is first accessed. (The persistence provider runtime is permitted to throw the EntityNotFoundException when getReference is called.)
getReference method are not required to be invoked within a transaction context
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.