Previously, merging a detached entity resulted in a SQL `insert` whenever there was no matching row in the database (for example, if the object had been deleted in another transaction).
This behavior was unexpected and violated the rules of optimistic locking.
An `OptimisticLockException` is now thrown when it is possible to determine that an entity is definitely detached, but there is no matching row.
For this determination to be possible, the entity must have either:
- a generated `@Id` field, or
- a non-primitive `@Version` field.
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.
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.
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,