Class PreferredConstructorDiscoveryUtil
Tuple into a DTO instance.
Compatibility is determined by constructor parameter order, parameter count, and runtime type assignability for each tuple element. Primitive constructor parameter types are normalized to their wrapper types before compatibility checks are performed.
When multiple constructors are compatible, a constructor annotated with
PersistenceCreator is preferred. Callers should keep at most one such
annotated constructor. If multiple annotated constructors are present, or if multiple non-annotated constructors
are compatible, constructor selection is not guaranteed to be stable and behavior is unpredictable.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Constructor<?>Finds a compatible constructor for the given tuple-backed DTO projection.
-
Constructor Details
-
PreferredConstructorDiscoveryUtil
public PreferredConstructorDiscoveryUtil()
-
-
Method Details
-
discover
public static Constructor<?> discover(@NonNull @NonNull Class<?> clazz, @NonNull @NonNull jakarta.persistence.Tuple tuple) Finds a compatible constructor for the given tuple-backed DTO projection.The selected constructor must declare the same number of parameters as the tuple contains elements, and each parameter must be assignable from the corresponding tuple element runtime Java type after primitive-wrapper normalization. Compatible constructors are evaluated in declared-constructor order, with a compatible constructor annotated with
PersistenceCreatortaking precedence over any previously found compatible constructor.If no compatible constructor exists, this method throws an
IllegalArgumentException. If multiple compatible constructors exist without a uniquely determining preference, the returned constructor depends on the current implementation details of discovery and should not be treated as stable API behavior.- Parameters:
clazz- target DTO type whose constructors should be inspectedtuple- tuple whose projected element count and runtime types drive compatibility checks- Returns:
- the compatible constructor selected for tuple-backed instantiation
- Throws:
IllegalArgumentException- if no suitable constructor can be found
-