使用Hibernate注释文本字段 [英] Text Field using Hibernate Annotation

查看:235
本文介绍了使用Hibernate注释文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法设置一个String类型,它会像

I am having trouble setting the type of a String, it goes like

public void setTextDesc(String textDesc) {
	this.textDesc = textDesc;
}

@Column(name="DESC")
@Lob
public String getTextDesc() {
	return textDesc;
}

和它没有工作,我检查了MySQL的架构,它仍然为varchar(255),我也试过,

and it didn't work, I checked the mysql schema and it remains varchar(255), I also tried,

@Column(name="DESC", length="9000")

@Column(name="DESC")
@Type(type="text")

我试图使类型为TEXT,任何想法是很好的AP preciated!

I am trying to make the type to be TEXT, any idea would be well appreciated!

推荐答案

您说我检查了MySQL的架构,它仍然为varchar(255) - 你以为休眠,自动改变你的数据库?它不会。即使你有 hibernate.hbm2ddl.auto 集,我不相信会休眠改变现有列的定义。

You said "I checked the mysql schema and it remains varchar(255)" - did you expect Hibernate to automatically alter your database? It won't. Even if you have hibernate.hbm2ddl.auto set, I don't believe Hibernate would alter the existing column definition.

如果你要产生新的数据库创建脚本, @Lob 应该产生TEXT类型的列,如果你没有指定明确的长度(或者如果你这样做,它的小于65536)。你总是可以强制通过在 @Column 标注明确声明的类型,但是请记住,这是数据库之间不可移植的:

If you were to generate new database creation script, @Lob should generate "TEXT" type column if you don't specify length explicitly (or if you do and it's less that 65536). You can always force that by explicitly declaring type in @Column annotation, though keep in mind that's not portable between databases:

@Column(name="DESC", columnDefinition="TEXT")

这篇关于使用Hibernate注释文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆