Join column must be defined with the same insertable and updatable attributes (HHH-17586)

Description

The problem was already reported half a year ago ( HHH-17586 ), but it got rejected because of “incorrect” usage of the @JoinColumn annotation.

The question was asked, why tha attribute updatable was set to false.

The answer is simple: Because hibernate-tools generates it like that. The method org.hibernate.mapping.Collection#hasAnyUpdatableColumns() always returns false. Therefore the code generation always sets updatable=false to the annotation.

Activity

Show:

SteGr May 15, 2024 at 7:26 AM

Code generation uses the classes from ORM (hibernate-core) and so the problem is in ORM.

The code generation detects a many-to-many relationship and creates the annotations @ManyToMany and @JoinTable.

  • [Tools] org.hibernate.tool.internal.export.java.EntityPOJOClass#generateCollectionAnnotation(Property, Metadata) uses Property#isUpdatable()

    • [ORM] org.hibernate.mapping.Property#isUpdatable()

      • [ORM] Forwards to org.hibernate.mapping.Value#hasAnyUpdatableColumns() (where the implementation is org.hibernate.mapping.Set implementing org.hibernate.mapping.Collection)

        • [ORM] org.hibernate.mapping.Collection#hasAnyUpdatableColumns() hardcodes the value to false while org.hibernate.mapping.Collection#hasAnyInsertableColumns() is hardcoded to true.
          This does not match the behaviour required by the new check.

But I will additionally create a Tools issue.

Marco Belladelli May 15, 2024 at 6:54 AM

this sounds like a code generation problem, not an ORM problem, so please open an issue on Hibernate Tools' Jira and link it to this one: https://hibernate.atlassian.net/browse/HBX. We can verify if something should be changed in ORM as well, but let’s take a look at Tools first.

SteGr May 15, 2024 at 6:47 AM

According to this commit, this was once set to return true, but changed back to false because of some bug.

SteGr May 15, 2024 at 6:11 AM

Sorry for the back and forth. I just realized that the class org.hibernate.mapping.Collection is part of ORM and not of Tools.

Presumably the only solution here is to change hasAnyUpdatableColumns() returning false to true. Because if the new check introduced with https://hibernate.atlassian.net/browse/HHH-17334 is to ensure that insertable == updatable, and hasAnyInsertableColumns() is true here, then hasAnyUpdatableColumns() must also be true.

Details

Assignee

Reporter

Affects versions

Priority

Created May 14, 2024 at 3:41 PM
Updated May 15, 2024 at 7:37 AM