开发者

Hibernate custom proxy generator - Stop equals() from initializing a lazy proxy

开发者 https://www.devze.com 2023-02-15 14:50 出处:网络
I have entity classes and these entity classes implement their own equals() function, which just compares the Ids of the classes. Sadly, invoking equals() on a Hibernate proxy initializes it, which is

I have entity classes and these entity classes implement their own equals() function, which just compares the Ids of the classes. Sadly, invoking equals() on a Hibernate proxy initializes it, which is completly useless in my case.

I use javassist as a proxy provider. Is there a way to modify the proxy generation code to not load the entity during an equals call, but instead does something else for me? Can I plug a custom proxy provider in Hibernate?

Please do not start 开发者_开发知识库a discussion on how equals should behave in Hibernate, this goes to far, there are different opinions on the topic, which I already know, and is not part of the question :).


It works if you override classes in the hibernate.jar, and providing your own Implementation of BasicLazyInitializer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号