hibernate中使用下划线生成列和表名 [英] Generated column and table names in hibernate with underscore
本文介绍了hibernate中使用下划线生成列和表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制hibernate生成db模式,使它将CamelCase转换为Underscores(使用HBM)?例如。我有:
<?xml version =1.0encoding =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>
我希望hibernate创建这样的表格(oracle):
(
BAR_BAZ_IDNUMBER(19,0)NOT NULL ENABLE,
$ b $
EXTRACT_CONTACT_TYPEVARCHAR2(512 CHAR),
- PK etc ...
)
我知道我可以在hbm.xml文件中使用表/列名,但是我想全局设置它(既节省时间又防止错误)。
解决方案
ImprovedNamingStrategy
应该完全按照你想要的。请参见 3.6。实施命名策略。
how do I force hibernate to generate db schema such that it converts CamelCase into Underscores (using HBM)? Eg. I have:
<?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):
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).
解决方案
ImprovedNamingStrategy
should do exactly what you want. See 3.6. Implementing a NamingStrategy.
这篇关于hibernate中使用下划线生成列和表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文