I would like to report this bug on the dedicated website, but I am unable to log in to the platform used for reporting bugs. Therefore, I can only seek assistance here.
I traced it to the source code, specifically in the createSimpleProperty
method of CopyIdentifierComponentSecondPass.class
, where it checks (firstColumn.isNameDeferred())
. The columnDefinition
of JoinColumn
only takes effect after the name
attribute of JoinColumn
is specified. I believe that it should also check whether columnDefinition
is specified, rather than only checking for name
.
While attempting to generate the DDL, I noticed that when a property references another entity, it defaults to reading the columnDefinition
of the id
attribute of the other entity.
@Entity
public class Entity2 {
@Id
@Column(columnDefinition = "bigint not null auto_increment comment 'ID'")
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
String name;
}
@Entity
public class Entity1 {
@Id
@Column(columnDefinition = "bigint not null auto_increment comment 'ID'")
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@JoinColumn(
foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT),
// name = "entity2_id",
columnDefinition = "bigint not null comment 'entity2 ID'"
)
@ManyToOne
Entity2 entity2;
}
I have provided the code for reproducing the issue.
In these two entities, there is a line that is commented out: // name = "entity2_id"
.
If the name
attribute is commented out, you will notice that the columnDefinition
in this JoinColumn
annotation does not take effect.
If you uncomment it, the columnDefinition
will work as expected.