java - CGLIB 如何代理 String 或其他 final 类?
问题描述
我想问一个关于 Hibernate 中的 Lazy Fetching 的问题。
据我所知,为了实现 Lazy Fetching,Hibernate 创建了一个占位符,它是真实属性的代理。
如果我的实体包含 String 属性或其他最终类怎么办?CGLIB 将如何对其进行子类化?
解决方案
长话短说:
- 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 来结束这个短语
推荐阅读
- c# - 如何对 List1 (int) 进行排序,以便相应的 List2 (string) 也进行排序?
- css - 可变宽度的图像条
- java - Cloud Dataflow:动态更改 bigquery 目标
- javascript - JSON.parse 里面有函数
- glassfish - jpa、persistence.xml、glassfish netbeans ide postgresql db pool an jdbc resource和jta的问题
- flutter - Flutter DraggableScrollableSheet - 如何以编程方式展开/折叠
- command-line - 如何在命令行中打开和编辑文件?
- javascript-objects - 是否可以将使用对象的函数的结果分配给 PHP 变量?
- angular - 对象数组作为 Material Angular 表的数据源
- codeigniter - 使用 Codeigniter 执行存储过程的问题