HHH-18285 Migration for emb-inheritance and annotated class validation
Also slight improvements to release notes and user guide.
This commit is contained in:
parent
e670f0bc4d
commit
40544fad60
|
@ -403,11 +403,11 @@ classes with `@DiscriminatorValue`.
|
|||
[IMPORTANT]
|
||||
====
|
||||
Embeddable inheritance *IS* also supported for components used in an `@ElementCollection`.
|
||||
Embeddable inheritance is *NOT* supported for `@EmbeddedId`, embeddable types used as `@IdClass`
|
||||
Embeddable inheritance *is NOT* supported for `@EmbeddedId`, embeddable types used as `@IdClass`
|
||||
and embedded properties using a custom `@CompositeType`.
|
||||
====
|
||||
|
||||
Note that the `type()` and `treat()` functions are also supported for embeddable inheritance, see <<chapters/jndi/QueryLanguage.adoc#hql-functions-typecasts,types and typecasts>>.
|
||||
Of course, the `type()` and `treat()` functions are also supported for embeddable inheritance and can serve to explicitly use the embeddable type information in queries, see <<chapters/jndi/QueryLanguage.adoc#hql-functions-typecasts,types and typecasts>>.
|
||||
|
||||
[[embeddable-inheritance-example]]
|
||||
.Example mapping of an embeddable inheritance hierarchy
|
||||
|
|
|
@ -70,14 +70,26 @@ For this determination to be possible, the entity must have either:
|
|||
|
||||
For entities which have neither, it's impossible to distinguish a new instance from a deleted detached instance, and there is no change from the previous behavior.
|
||||
|
||||
[[embeddable-treated-paths]]
|
||||
== Changes to the `SqmTreatedPath` interface
|
||||
[[mapped-superclass-embeddable]]
|
||||
== Explicit validation of annotated class types
|
||||
Hibernate has always been lax when it comes to `@Embedded` property types, allowing classes not annotated with `@Embeddable` to still work correctly. This is a nice feature that enables you to map your attributes to classes that you cannot modify to add the annotation, and will continue to work as expected in the future.
|
||||
|
||||
ORM 6.6 introduced support for `@Embeddable` type inheritance.
|
||||
With it, we also enabled the `type()` and `treat()` functions to work with embeddable-typed paths.
|
||||
As a consequence, the `SqmTreatedPath#getTreatTarget()` method will now return a generic `ManagedDomainType` object,
|
||||
One consequence of this, though, was letting you use both `@MappedSuperlcass` and `@Embeddable` on the same annotated class as a workaround to enable having subclasses annotated as `@Embeddable` and still use both types in embedded attribute mappings. This has never been officially supported, with things like the JPA static metamodel not working as expected, and starting from 6.6 we will explicitly validate that mapped classes are annotated _either_ `@MappedSuperclass` _or_ `@Embeddable`, _or_ `@Entity`.
|
||||
|
||||
Extending a `@MappedSuperclass` annotated class with an `@Embeddable` type is still supported, but we suggest keeping the two annotated class types separate. You can now also take advantage of explicit discriminator column based <<embeddable-inheritance,embeddable inheritance>>.
|
||||
|
||||
[[embeddable-inheritance]]
|
||||
== Discriminator-based embeddable inheritance
|
||||
|
||||
ORM 6.6 introduced support for `@Embeddable` type inheritance, always relying on a discriminator column stored within the entity mappings that contain the polymorphic `@Embedded` property of that type.
|
||||
Note that this functionality will be automatically enabled for all `@Embedded` properties whose type (Java class) is extended by subclasses annotated with `@Embeddable`. Previously, `@Embeddable`-annotated subtypes were always ignored, so this should not impact your mappings, unless you were using the "workaround" described in the <<mapped-superclass-embeddable,previous chapter>>.
|
||||
|
||||
With embeddable inheritance, we also enabled the `type()` and `treat()` functions to work with embeddable-typed paths.
|
||||
As a consequence, the `org.hibernate.query.sqm.tree.domain.SqmTreatedPath#getTreatTarget()` method will now return a generic `ManagedDomainType` object,
|
||||
which could in turn be an `EntityDomainType` (as it was before) or also an `EmbeddableDomainType` instance.
|
||||
|
||||
You can find more details about embeddable inheritance in the dedicated link:{userGuideBase}#embeddable-inheritance[user guide chapter].
|
||||
|
||||
[[h2-dialect]]
|
||||
== H2 database and bulk mutation strategy
|
||||
|
||||
|
|
|
@ -199,6 +199,8 @@ create table TestEntity (
|
|||
)
|
||||
----
|
||||
|
||||
You can choose to customize the discriminator column properties using the `@DiscriminatorColumn` annotation on the root embeddable type, and you can pick the discriminator values to use for each subtype with the `@DiscriminatorValue` annotation, just like with entities.
|
||||
|
||||
For more detailed information please refer to the link:{user-guide-url}#embeddable-inheritance[Embeddable inheritance] user guide chapter.
|
||||
|
||||
[[oracle-vector]]
|
||||
|
|
Loading…
Reference in New Issue