Search code examples
javahibernatejpajavassist

Inspecting the generated proxy classes in hibernate JPA


When using JPA / Hibernate, classes annotated with @Entity can be more-or-less transparently stored, queried, retrieved, and so on from a database.

However, when you operate with an instance retrieved via JPA, you are actually operating with a proxy object, of a class created by the JPA provider (in my case, Hibernate) when the application was started.

Is it possible to inspect / decompile this generated proxy class, out of sheer curiosity? One option is to look up and patch the sources from Hibernate itself - however, I would rather run the application and dump and/or locate the generated classes directly.

Hibernate uses javassist as a bytecode provider.


Solution

  • Hibernate can also do bytecode weaving at compile time. Since this is created at compile time it, it is much easier to decompile and inspect the woven classes.

    https://docs.jboss.org/hibernate/orm/5.0/topical/html/bytecode/BytecodeEnhancement.html