我想问一个关于 Hibernate 中的 Lazy Fetching 的问题。据我所知,为了实现 Lazy Fetching,Hibernate 创建了一个占位符,它是不动产的代理。如果我的实体包含 String 属性或其他最终类怎么办?CGLIB 将如何子类化它?
1 回答
![?](http://img1.sycdn.imooc.com/545868b60001587202200220-100-100.jpg)
森林海
TA贡献2011条经验 获得超2个赞
长话短说:
CGLib 根本无法代理最终类,您之前可能在日志中看到过类似的内容 Could not generate CGLIB subclass of class [class SomeClass]: Common causes of this problem include using a final class or a non-visible class
Hibernate 首先代理您的实体类,将相应的属性拦截器注入到相应的 getter 中,因此实际的调用堆栈通常如下所示:
myEntity.getMyString()
|_ proxy.getMyString()
|_ lazyAttributeLoadingInterceptor.fetchAttribute(myEntity,"myString")
|_ ... (actual call to underlying DB if required)
也就是说,你在这里陈述的一切都是正确的:
Hibernate 创建了一个占位符,它是真实...
如果你用entity / pojo而不是property来结束这个短语
添加回答
举报
0/150
提交
取消