I was going through the documentation for hibernate and found these lines
The no-argument constructor is a requirement for all persistent classes; Hibernate has to create objects for you, using Java Reflection. The constructor can be private, however package or public visibility is required for runtime proxy generation and efficient data retrieval without bytecode instrumentation
Can anyone please explain the runtime proxy generation and efficient data retrieval without bytecode instrumention
Runtime proxy means that Hibernate will wrap your class with a Proxy class. You can see in debugger, that instantiated objects are not of your type but of some proxy one.
To do so, Hibernate needs to override your class. The parameterless constructor is needed to call base()
constructor. Hibernate doesn't know how to fill your custom parameters. Other think is to make all your properties and methods virtual
so they can be overridden too.
Think of it like you have third party library (one containing your persistent classes) and now you need to add some general functionality to them, without reading the doc and analyzing class by class, property by property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With