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?
-
To use the proxy creator that is in java, yes, you are correct, but I believe hibernate uses CGLib to generate its proxies.
Its a cool program, and doesn't require interfaces to generate a proxy.
(and maybe someday hibernate will move to using AOP and the world will be a better place).
Vladimir Dyuzhev : yes, it does use cglib -
Since Hibernate 3.3, the default bytecode provider is now Javassist rather than CGLib.
-
See class javassist.util.proxy.ProxyFactory for details.
-
Hibernate uses the bytecode provider configured in
hibernate.properties
, for example:hibernate.bytecode.provider=javassist
0 comments:
Post a Comment