@Target deprecated but still needed?

@Target has been deprecated since 6.2, but still is referenced in the docs as a way to let Hibernate known the concrete type to use for embeddables in some cases.

I have a scenario where I’m using it to resolve a generic ambiguity and I’m not aware of any other easy alternative, other than perhaps creating a custom EmbeddableInstantiator, but that seems overkill.

E.g.

//Embeddable hierarchy
abstract sealed class Payment permits Payment1, Payment2 {}
class Payment1 extends Payment {}
class Payment2 extends Payment {}

abstract class SomeEntity<T extends Payment> {
    @Target(Payment.class) // Must use @Target b/c Hibernate can't figure out T bounds
    T payment;
}

Without @Target, what’s the Hibernate idiomatic way of solving this problem?

In ORM 7.0, a new annotation called TargetEmbeddable was introduced as part of HHH-18198

1 Like