java 用下划线在休眠中生成的列和表名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5243711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generated column and table names in hibernate with underscore
提问by Ondrej Skalicka
how do I force hibernate to generate db schema such that it converts CamelCase into Underscores (using HBM)? Eg. I have:
如何强制休眠生成数据库模式,以便将 CamelCase 转换为下划线(使用 HBM)?例如。我有:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cz.csas.pdb.be.model.product.passive">
<class name="foo.BarBaz">
<id name="barBazId">
<generator class="sequence"/>
</id>
<property name="extractContactType"/>
<!-- ... -->
</class>
</hibernate-mapping>
And I want hibernate to create table like this (oracle):
我希望休眠创建这样的表(oracle):
CREATE TABLE "BAR_BAZ"
(
"BAR_BAZ_ID" NUMBER(19,0) NOT NULL ENABLE,
"EXTRACT_CONTACT_TYPE" VARCHAR2(512 CHAR),
-- PK etc...
)
I know I can use table/column name in the hbm.xml file, but I want to set it globally (both to save time and prevent errors).
我知道我可以在 hbm.xml 文件中使用表/列名称,但我想全局设置它(既节省时间又防止错误)。
回答by axtavt
ImprovedNamingStrategy
should do exactly what you want. See 3.6. Implementing a NamingStrategy.
ImprovedNamingStrategy
应该做你想做的。见3.6。实施命名策略。
回答by Andrea Ligios
In JPA 2(Hibernate 4), it is even more easier, just add:
在JPA 2(Hibernate 4) 中,它更容易,只需添加:
<property name="hibernate.ejb.naming_strategy"
value="org.hibernate.cfg.ImprovedNamingStrategy" />
to your persistence.xml
.
到您的persistence.xml
.