[英]Spring Hibernate MySQL Unidirectional ManyToOne
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. 原始的obs字段没有注释,因此Hibernate将其创建为varchar(255),但我需要它能够处理更大的文本。 After the changes (as shown above), the method getParent() always returns null.
更改之后(如上所示),方法getParent()始终返回null。
Does anyone have any idea why this is happening? 有谁知道为什么会这样吗?
For your Column
annotation, rather than using columnDefinition
set the length
element. 为您的
Column
注解,而不是使用columnDefinition
设置length
元素。 Here is the Javadoc of length
: 这是
length
的Javadoc:
(Optional) The column length.
(可选)列长。 (Applies only if a string-valued column is used.)
(仅在使用字符串值的列时适用。)
Default:
默认:
255
255
You can also see why it defaulted to VARCHAR(255)
in your schema: the default is 255. Why your columnDefinition
doesn't work, however, I don't know (I've no experience with it). 您还可以查看为什么它在您的模式中默认为
VARCHAR(255)
:默认值为255。为什么您的columnDefinition
不起作用,但是,我不知道(我对此没有经验)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.