问题描述
据我所知,创建动态 Java 代理需要有一个接口来为代理工作.然而,Hibernate 似乎无需为实体类编写接口即可管理其动态代理生成.它是如何做到这一点的?Hibernate 文档中的唯一线索是,类必须至少有一个包可见的构造函数来生成代理.
To the best of my knowledge, creating a dynamic Java proxy requires that one have an interface to work against for the proxy. Yet, Hibernate seems to manage its dynamic proxy generation without requiring that one write interfaces for entity classes. How does it do this? The only clue from the Hibernate documentation refers to the fact that classes must have at minimum a package-visible constructor for proxy generation.
Hibernate 是否使用自定义类加载器进行运行时字节码工程?文档表明情况并非如此.那么他们如何围绕具体实体对象创建代理包装器呢?他们是否只是创建了一些琐碎接口的代理而不考虑类型安全,然后根据需要进行转换?
Is Hibernate doing runtime bytecode engineering with a custom classloader? The documentation suggests that this is not the case. So how do they create their proxy wrappers around the concrete entity objects? Do they just create a proxy of some trivial interface without concern for type safety and then cast it as desired?
推荐答案
从 Hibernate 3.3 开始,默认的字节码提供程序现在是 Javassist 而不是 CGLib.
Since Hibernate 3.3, the default bytecode provider is now Javassist rather than CGLib.
这篇关于Hibernate 如何创建具体类的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!