在介绍文档里看到这么一段:
-
The
no-argument
constructor, which is also a JavaBean convention, is a requirement for all persistent classes. Hibernate needs to create objects for you, using Java Reflection. The constructor can be private. However, package or public visibility is required for runtime proxy generation and efficient data retrieval without bytecode instrumentation.
package visibility 的 constructor 要做动态代理,要看一下hibernate怎么解决的,我猜hibernate的动态代理加载想办法用了跟原 java bean class 同一个 ClassLoader,不然package visibility 跨 ClassLoader 是不行的。有时间专门去看一下 hibernate 动态类加载是用了什么实现。