Hibernate数据库特定的columnDefinition值 [英] Hibernate database specific columnDefinition values

查看:413
本文介绍了Hibernate数据库特定的columnDefinition值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题如下:我们使用hibernate和注解作为O / R映射器。



一些@Column注释看起来像:



@Column(columnDefinition =longblob,name =binaryData,nullable = true)





@Column(columnDefinition =mediumtext,name =remark,nullable = true) $ b

,其中columnDefinition属性是特定于mysql的



在postgres上,columnDefinition值应该是bytea和varchar(999999)

和oracle可能是其他的东西。



出现问题目前在模式导出时,例如当创建DDL语句时。



我能想到的可能的解决方法是
- 扫描一些执行文本替换的JDBC驱动程序(例如longblob-> bytea)为DDL语句。这是丑陋的,但会以某种方式工作
- 使用hibernate xml配置而不是注释。这可能会工作,但我更喜欢注释



有人知道任何替代品吗? Hibernate特定的解决方法可以,例如如果columnDefinition属性可以包含特定于方言的值,如
$ b $ p $ lt; code> @Column(columnDefinition =mysql-> mediumtext,postgres-> varchar(999999 ),name =remark,nullable = true)



感谢
Holger
<为什么不使用数据库不可知的注释,比如:


  • > @Lob (在一个字节[] 或一个字符串 property

  • @Column(length = 90000)(在 String property)



并查看数据库中将生成哪些列。他们很可能是你想要他们的类型。

the problem is as follows: We're using hibernate with annotations as O/R Mapper.

Some @Column annotations look like:

@Column(columnDefinition = "longblob", name = "binaryData", nullable = true)

or

@Column(columnDefinition = "mediumtext", name = "remark", nullable = true)

with the columnDefinition attributes being mysql specific

on postgres for example, the columnDefinition values should be "bytea" and "varchar(999999)"

and on oracle probably something else.

Problems arise currently at the time of Schema Export, e.g. when creating the DDL statements.

Possible workarounds that I can think of are - Hack some JDBC driver that does a text replace (e.g. longblob->bytea) for the DDL statements. That's ugly but will work somehow - Use hibernate xml configuration instead of annotations. That will probably work but I prefer annotations

Does anybody know any alternatives? Hibernate specific workarounds are ok, e.g. if the columnDefinition attribute can contain dialect specific values like

@Column(columnDefinition = "mysql->mediumtext, postgres->varchar(999999)", name = "remark", nullable = true)

Thanks Holger

解决方案

Why don't you use the database-agnostic annotations like:

  • @Lob (on a byte[] or a String property)
  • @Column(length=90000) (on a String property)

and see what columns will be generated in the database. They will most likely be of the types you want them to be.

这篇关于Hibernate数据库特定的columnDefinition值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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