I have two (very simple) entities: Parent and Child.
@Entity
class Child {
@Id
@Column(name = "id", nullable = false, updatable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(columnDefinition="varchar(4000)")
private String obs;
@NotNull
@ManyToOne(optional = false)
@JoinColumn(nullable = false, updatable = false)
private Parent parent;
(getters and setters)
}
The original obs field had no annotation, so Hibernate created it as a varchar(255), but I needed it to be able to handle a larger text. After the changes (as shown above), the method getParent() always returns null.
Does anyone have any idea why this is happening?
For your
Column
annotation, rather than usingcolumnDefinition
set thelength
element. Here is the Javadoc oflength
:You can also see why it defaulted to
VARCHAR(255)
in your schema: the default is 255. Why yourcolumnDefinition
doesn't work, however, I don't know (I've no experience with it).