The following happened after our upgrade from 5.0.3 to 5.1.0.Final First, we normally use a double @ManyToOne mapping, e.g. one property maps the entity and the other one only the ID. This because sometimes, on a LAZY association, we want to retrieve only the id of the parent object without having Hibernate fetch the whole object. So we map both properties on the same column. Given the following @OneToMany mapping
@ManyToOne(fetch = FetchType.EAGER,
optional = true,
targetEntity = Parent.class)
@JoinColumn(name = "PARENT_ID",
nullable = true,
foreignKey = @ForeignKey(name = "CHILD_TO_PARENT",
value = ConstraintMode.CONSTRAINT) )
private Parent parent;
@Column(name = "PARENT_ID",
nullable = true,
insertable = false,
updatable = false)
private final String parentId = null;
In version 5.0.3 the SchemaCreate would automagically guess that the length of Parent's PK column is 2 and generate a column of length 2 So I get a SQL create statement like
CREATE TABLE CHILD (....., PARENT_ID VARCHAR(2).....);
ALTER TABLE CHILD ADD CONSTRAINT....
Works good. After upgrade to Hibernate 5.1.0.Final the PARENT_ID column is generated VARCHAR(255) so the ADD CONSTRAINT statement will fail. I need to explicitly (this is why I commented out the length attribute in @Column annotation in my code) set the length to each and every @Column. Withut setting the length of every FK column, I get an error executing the ADD CONSTRAINT statement. If someone has an idea about where to look in the Hibernate code I could take that look personally and hopefully make a PR. |