简体   繁体   中英

how to check if record exists using hibernate

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM