对弹簧数据进行类似的加载并获取休眠方法 [英] similar load and get hibernate method on spring data

查看:58
本文介绍了对弹簧数据进行类似的加载并获取休眠方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关Hibernate和使用Spring数据的信息.在第一章中,我了解了get()和load()的不同之处,据推测,在Hibernate中,load返回一个proxy placeHolder代理,并且仅在访问实体属性的情况下才访问数据库. 在我的应用程序中,很多时候我只需要返回并添加实体作为对另一个实体的依赖关系,对于这种特定情况,添加一个代理就绰绰有余,但是使用Spring数据存储库我找不到get()或load()方法,所以我猜他们没有实现与Hibernate中相同的功能.知道Spring数据是否具有Hibernate的功能以具有proxy placeHolder吗?

I´m reading about Hibernate and using Spring data. In one chapter I´ve read about the different of use get() and load(), supposedly in Hibernate load return a proxy placeHolder and only access to database in case that you access to the entity attribute. In my application many times I just need to return and entity to add as dependency to another entity and for that specific case add a proxy would be more than enough, but using Spring data repository I cannot find the get() or load() method, so I guess they dont implement the same feature as in Hibernate. Any idea if Spring data has that Hibernate´s features to have a proxy placeHolder?.

致谢.

推荐答案

JpaRepository接口有两种方法:第一种是getOne(id),它是休眠加载的替代方法;第二种是findById(id),它是休眠get的替代方法.方法.

JpaRepository interface has two methods: First is getOne(id) which is an alternative of hibernate load, second is findById(id) which is an aternative of hibernate get method.

这篇关于对弹簧数据进行类似的加载并获取休眠方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆