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

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

问题描述

我在设置字符串类型时遇到问题,就像

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,任何想法将不胜感激!

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

推荐答案

您说我检查了 mysql 架构,它仍然是 varchar(255)" - 您是否希望 Hibernate 自动更改您的数据库?不会.即使您设置了 hibernate.hbm2ddl.auto,我也不相信 Hibernate 会改变现有的列定义.

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 如果您没有明确指定长度(或者如果您指定长度并且小于 65536),则 @Lob 应该生成TEXT"类型的列.您始终可以通过在 @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 Annotation 的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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