Hibernate如何创建具体类的代理? [英] How does Hibernate create proxies of concrete classes?

查看:186
本文介绍了Hibernate如何创建具体类的代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,创建动态Java代理需要有一个接口来处理代理。然而,Hibernate似乎管理其动态代理生成,而不需要为实体类编写一个接口。它是如何做到的? Hibernate文档中唯一的线索是指类必须至少有一个用于生成代理的包可见构造函数。



Hibernate是否使用自定义进行运行时字节码工程类加载器?文件表明情况并非如此。那么他们如何创建围绕具体实体对象的代理包装呢?他们只是创建一个简单的接口的代理,而不考虑类型安全性,然后根据需要进行转换?

解决方案

由于Hibernate 3.3 ,默认字节码提供程序现在是Javassist而不是CGLib。


$ b

Hibernate核心迁移指南:3.3


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.

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?

解决方案

Since Hibernate 3.3, the default bytecode provider is now Javassist rather than CGLib.

Hibernate Core Migration Guide : 3.3

这篇关于Hibernate如何创建具体类的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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