简体   繁体   English

如何使用休眠检查记录是否存在

[英]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. 如果请求的实例在数据库中不存在,则在首次访问实例状态时将引发EntityNotFoundException。 (The persistence provider runtime is permitted to throw the EntityNotFoundException when getReference is called.) (在调用getReference时,允许持久性提供程序运行时引发EntityNotFoundException。)

getReference method are not required to be invoked within a transaction context 不需要在事务上下文中调用getReference方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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