Fix for HHH-9864 causes "MappingException: collection was not an association" with hibernate.order_inserts=true and component association

Description

After upgrading to 5.2.4 we started getting weird "org.hibernate.MappingException: collection was not an association: com.renxo.cms.domain.network.ShortCode.localizedFields" when saving new entity instances for some of our mapped classes. Previously we were running 5.2.3 without any issues.

The property in question is mapped like this:

@Override
@Audited
@AuditJoinTable(name = "short_code_locale_aud")
@MapKeyType(value = @Type(type = "locale"))
@MapKeyClass(LocaleType.class)
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "short_code_locale", joinColumns = @JoinColumn(name = "short_code_id", nullable = false, foreignKey = @ForeignKey(name = "sh_code_sh_code_loc_fk")))
@MapKeyColumn(name = "locale", length = 12, nullable = false)
@BatchSize(size = 100)
@Fetch(FetchMode.SELECT)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public Map<Locale, LocalizedFields> getLocalizedFields() {
return localizedFields;
}

See the attached stack trace. This seems likely related to the changes introduced by at org.hibernate.engine.spi.ActionQueue$InsertActionSorter.addParentChildEntityNames() which seems to be assuming that all inserts are related to entity names without considering that inserts may also be cause by component collections, such as our case.

In the meantime, we're working around this issue by disabling hibernate.order_inserts in hibernate.properties

Environment

None

Status

Assignee

Unassigned

Reporter

Manuel Dominguez Sarmiento

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure