问题描述
我有一个JPA / Hibernate数据模型,我使用Hibernate hbm2ddl工具来生成数据库DDL。我有一些字符串应该是CHAR和一些可能是数据库中的VARCHAR。我想尽量减少手动编辑的DDL(我意识到,有些将必须发生)。
I have a JPA/Hibernate data model that I am using the Hibernate hbm2ddl tool to generate database DDL. I have some strings that should be CHAR and some that may be VARCHAR in the database. I want to minimize hand editing of the DDL (I realize that some will have to happen).
任何人都知道我该怎么走?我意识到,我可以通过一个黑客方言使所有字符串VARCHARS或CHARS,但这不是在数据库中总是适当的。
Anyone know how I should go about this? I realize that I can make all Strings VARCHARS or CHARS via a hacked dialect, but that isn't what is always appropriate in the database.
我想能够
感谢。
推荐答案
所以,我终于发现你可以为方言中的类型指定长度限制。所以,我已经决定任何长度为10的应该是char,任何事情应该是varchar:
So, I finally found that you can specify a length limit for a type in the dialect. So, I've decided that anything under a length of 10 should be char and anything over that should be varchar:
registerColumnType( Types.VARCHAR, 10, "char($l)" );
这不是我想要的,但这是不够的。可悲的是,我以前没有发现。
That isn't exactly what I was wanting, but that is good enough. Sad that I didn't find that earlier.
这篇关于JPA / Hibernate DDL生成; CHAR vs. VARCHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!