Reputation: 109
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
Upvotes: 5
Views: 706
Reputation: 2497
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.
Upvotes: 5