xmolecules / jmolecules-integrations

Technology integration for jMolecules
Apache License 2.0
85 stars 23 forks source link

Prevent JPA enhancement from processing CGLib proxy classes #190

Closed odrotbohm closed 1 year ago

odrotbohm commented 1 year ago

Domain types might be subject to CGLib proxy creation. For example, such a proxy might be created in the context of a GraalVM native build and effectively shadows the original domain type. If we process such types as well, they will become subject to processing by Hibernate which then might break (read: breaks) not knowing how to deal with the additional interfaces introduced by the proxying step.

Case in point: in Spring RESTBucks, we register the Drink aggregate for proxying and reflection in an AOT-specific callback. This results in a hard to debug error upon second execution. The first (clean) execution processes all standard types and adds the JPA annotations to those. In case of some AOT related execution (AOT itself or a native build), the proxy type is generated after the processing. A subsequent build will then make that proxy generated in the first build subject to our enhancement, add JPA annotations on that as well and Hibernate will then fail to process org.springframework.cglib.proxy.MethodInterceptor, an interface that the proxy implements.