hibernate - Spring Data Jpa:OneToOne mappedBy 属性始终返回 null
问题描述
我的应用程序中有几个@OneToOne
关系,它们都有相同的问题。一个例子:
实体 1:
@Entity
class OfferPagePanel(
@OneToOne
var offerPage: OfferPage,
)
实体 2:
@Entity
abstract class OfferPage(
var title: String
){
@OneToOne(mappedBy="page")
var ogTag: OgTag? = null
@OneToOne(mappedBy="offerPage")
var panel: OfferPagePanel? = null
}
问题:
fun someServiceFunction(){
offerPage.panel //This is always null, even though a matching panel is in the database
offerPagePanelRepository.findByPage(offerPage) //this returns the correct panel
}
(如果你想知道的话,KT 中的语法)
解决方案
嗯..我做到了
val offerPage = repository.getOne(id)
但这基本上返回一个空壳。一旦通过findOne(id)
它加载,一旦属性被调用,Hibernate 就可以使用代理加载实体......
推荐阅读
- html - 在 CodePen 上调整窗口大小导致滚动条出现在全屏画布上
- android - 使用 Firebase 身份验证的 Flutter Web Dev:MissingPluginException
- pip - 安装 pygame 时如何处理“没有名为 pygame 的模块”?
- excel - VBA选择全部并取消选择0和空白过滤器以跨多个工作表进行数据透视表
- node.js - 带有strapi的电子,找不到模块package.json
- digital-ocean - 非启动 Rails 5.2 应用程序 - ActiveSupport::MessageEncryptor::InvalidMessage
- github - 如何将文件上传到 https://github.com/downloads/
/ /? - python - 使 KivyMD android 应用程序适合所有屏幕尺寸
- python - 如何使用 Selenium 和 python 从 Tradingview 网站单击“加载更多”按钮?
- flutter - 如何修复此错误:预期标识符.dart