Java hibernate:如何将列varchar设置为max?
我有一列Java hibernate:如何将列varchar设置为max?,java,mysql,hibernate,Java,Mysql,Hibernate,我有一列字符串post 我想把这个post映射成一个字符串 我正在使用: @Column(updatable = true, name = "Post", nullable = false, length=50) public String getPost() { return post; } 此代码映射varchar(50) 如何映射varchar(max) 我试试这个代码。但我不能编译它 @Column(updatable = true, name = "P
字符串post
我想把这个post
映射成一个字符串
我正在使用:
@Column(updatable = true, name = "Post", nullable = false, length=50)
public String getPost() {
return post;
}
此代码映射varchar(50)
如何映射varchar(max)
我试试这个代码。但我不能编译它
@Column(updatable = true, name = "Post", nullable = false, length=max)
public String getPost() {
return post;
}
感谢您的回复。这可以使用以下代码完成:
@Column(updatable = true, name="Post", nullable = false, columnDefinition = "varchar(max)")
private String post;
还没有尝试过这个,但它应该在此基础上工作
UPD#1
基本上,您可以添加注释@Lob
,或者在@Column
中为长度使用非常大的值
发件人:
@Lob
表示应根据属性类型将属性持久化到Blob或Clob中:java.sql.Clob
,Character[]
,char[]
和java.lang.String
将持久化到Clob中java.sql.Blob
、Byte[]
、Byte[]
和serializable类型将持久保存在Blob中
这可以使用以下代码完成:
@Column(updatable = true, name="Post", nullable = false, columnDefinition = "varchar(max)")
private String post;
还没有尝试过这个,但它应该在此基础上工作
UPD#1
基本上,您可以添加注释@Lob
,或者在@Column
中为长度使用非常大的值
发件人:
@Lob
表示应根据属性类型将属性持久化到Blob或Clob中:java.sql.Clob
,Character[]
,char[]
和java.lang.String
将持久化到Clob中java.sql.Blob
、Byte[]
、Byte[]
和serializable类型将持久保存在Blob中
试着这样写:
@Column(updatable = true,name="Post",nullable = false,columnDefinition = "varchar(255)")
public String getPost() {
return post;
}
欲了解更多信息,请访问尝试这样写:
@Column(updatable = true,name="Post",nullable = false,columnDefinition = "varchar(255)")
public String getPost() {
return post;
}
有关更多信息,请转到我不认为50是最大值。我不认为50是最大值。我尝试了您的代码,但此代码没有映射我的表。我尝试了您的代码,但此代码没有映射我的表。