Join column must be defined with the same insertable and updatable attributes (HHH-17586)
Description
Activity
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)
usesProperty#isUpdatable()
[ORM]
org.hibernate.mapping.Property#isUpdatable()
[ORM] Forwards to
org.hibernate.mapping.Value#hasAnyUpdatableColumns()
(where the implementation isorg.hibernate.mapping.Set
implementingorg.hibernate.mapping.Collection
)[ORM]
org.hibernate.mapping.Collection#hasAnyUpdatableColumns()
hardcodes the value tofalse
whileorg.hibernate.mapping.Collection#hasAnyInsertableColumns()
is hardcoded totrue
.
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
@SteGr 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.
@Marco Belladelli 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
.
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 tofalse
.The answer is simple: Because hibernate-tools generates it like that. The method
org.hibernate.mapping.Collection#hasAnyUpdatableColumns()
always returnsfalse
. Therefore the code generation always setsupdatable=false
to the annotation.