Why JPA Entity or Hibernate Persistence Class Should Not be Final?

Yes, a Hibernate Entity class can be declared final, however it is not a good practice.

Hibernate uses the proxy pattern for performance improvement during lazy association, by making an entity final, Hibernate will no longer be able to use a proxy as Java doesn’t allow the final class to be extended.

Important points to about Entity class, Final, and Proxying

3) As per Hibernate documentation, if you’re going to make a class final you should explicitly disable proxy generation by adding @Proxy(lazy=false), but I haven’t noticed any differences between doing that and just making the class final.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sanjay Singh

Java||Spring-Boot|| Micro services Application developer|| INDIA