5

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Nice and well explained answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.