Hibernate postgresql / hsqldb TEXT列不兼容问题 [英] Hibernate postgresql/hsqldb TEXT column incompatibility problem

查看:182
本文介绍了Hibernate postgresql / hsqldb TEXT列不兼容问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Hibernate和PostgreSQL进行生产和HSQLDB测试存在问题。
我使用自顶向下的方法让Hibernate创建数据库模式。

我也是使用注释;映射部分的hibernate.cfg.xml只包含如下行:

< mapping class =package.subpackage.ClassName/> />
Hibernate默认将字符串变量设置为PostgreSQL上不同的字符(255),这在某些情况下对我来说不够用,所以我必须使用

@Column(columnDefinition =TEXT)。

但是,TEXT类型对HSQLDB无效,所以无法创建这些表。


任何人都可以帮助解决这个问题吗?解决方案

解决方案

最简单的方法来处理这个特定的问题可能是根本不使用columnDefinition,而是使用(例如)显式指定列长度

  @列(长度= 10000)

也可以将其映射为
@Lob(type = LobType.CLOB)

但我不确定在HSQLDB中是否支持正确。在Postgres中它应该给你你的TEXT类型。


I have a problem using Hibernate and PostgreSQL for production and HSQLDB for testing.
I am using top-down approach letting Hibernate create database schema.
I am also using annotations; mapping part of hibernate.cfg.xml only contains lines like
<mapping class="package.subpackage.ClassName" />
Hibernate defaults String variables to character varying(255) on PostgreSQL which is not sufficient for me in some cases, so I have to redefine some columns manually using
@Column(columnDefinition = "TEXT").
But, TEXT type is invalid for HSQLDB, so those tables can not be created.

Can anyone help to solve this?

解决方案

The easiest way to deal with this specific issue is probably to not use the columnDefinition at all and instead to explicitly specify the column length with (for example)

@Column(length=10000)

It might also be that you could instead map it with @Lob(type = LobType.CLOB)

but I'm not sure that is supported properly in HSQLDB. In Postgres it should give you your TEXT type.

这篇关于Hibernate postgresql / hsqldb TEXT列不兼容问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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