[hibernate-dev] HHH-9440 Support for Java 8: parameter names

Lovro Pandzic lovro.pandzic at gmail.com
Fri Mar 18 03:32:16 EDT 2016


Hello,

I'd like to discuss issue HHH-9440.

Basic idea behind this issue is that we try to and eliminate the
requirement for no arg constructor on entities or at least weaken that
requirement to specific cases.
Construction from both the user code and the hibernate itself would go
through user specified constructors.
This would enable use cases like enforcing invariants in constructors,
immutable entities and in the long run, maybe even support for value types
coming in Java 10 that, at least for now, we know will be immutable and
won't have a no arg constructor.

By using parameter names and Java 8 API you can, for instance, map those
parameter names to fields to find out column mappings and other information
required for mapping arguments to parameters.

A similar approach like this is used by jackson-databind with the
jackson-module-parameter-names (this will soon be integrated into the
jackson-databind itself). Another example, Spring also uses parameter names
to map bean names to parameters in constructors.

There are border cases like the one Steve mentioned in the issue:

> How would you see lazy loading working then?
>

>From my perspective, there are 2 approaches here:
- use a library like Objenesis that enables you to construct classes
without using the constructor
- document that all entities that are to be proxied must have a no arg
constructor

What do you guys think?


More information about the hibernate-dev mailing list