![](/img/trans.png)
[英]Spring 1.4.0 release hibernate naming strategy will add underscore(_) to table and column names
[英]Generated column and table names in hibernate with underscore
如何強制hibernate生成數據庫模式,以便將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>
我希望hibernate創建這樣的表(oracle):
CREATE TABLE "BAR_BAZ"
(
"BAR_BAZ_ID" NUMBER(19,0) NOT NULL ENABLE,
"EXTRACT_CONTACT_TYPE" VARCHAR2(512 CHAR),
-- PK etc...
)
我知道我可以在hbm.xml文件中使用表/列名,但我想全局設置它(既節省時間又防止錯誤)。
ImprovedNamingStrategy
應該完全符合您的要求。 見3.6。 實現NamingStrategy 。
在JPA 2 (Hibernate 4)中, 它更容易 ,只需添加:
<property name="hibernate.ejb.naming_strategy"
value="org.hibernate.cfg.ImprovedNamingStrategy" />
到你的persistence.xml
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.