我是hibernate的新手,我使用Netbeans示例项目生成了POJO表单数据库。一切似乎都正常,但在hbn和java文件中没有外键名称,这是一个问题,因为我想从POJO文件开始生成模式DDL
我的hibernate.cfg.xml
r.Dial customer_number,
:method => 'POST',
:timeout => '30',
:calledId => "YOUR_VERIFIED_NUMBER"
hibernate.reveng.xml中
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@server1:1521:orcl</property>
<property name="hibernate.connection.username">TABLE_OWN</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.default_schema">TABLE_OWN</property>
</session-factory>
</hibernate-configuration>
原始DDL
<hibernate-reverse-engineering>
<schema-selection match-schema="TAB_OWN"/>
<table-filter match-name="TABLE1"/>
<table-filter match-name="TABLE2"/>
<table-filter match-name="TABLE3"/>
</hibernate-reverse-engineering>
hibernate生成的hbm文件
CREATE TABLE BJADRE
(
RE_ADID varchar(14) NOT NULL,
RE_ADID_SEQ varchar(2) NOT NULL,
RE_ADSTAT varchar(1) NOT NULL,
RE_ADFROM varchar(6) NOT NULL,
RE_ADOPNO decimal(22,0) NOT NULL,
RE_JSNAME varchar(16) DEFAULT ' ' NOT NULL,
RE_REOPNO decimal(22,0) DEFAULT 0 NOT NULL,
RE_COMPL varchar(1) DEFAULT ' ' NOT NULL,
RE_JOBNAME varchar(40) DEFAULT ' ' NOT NULL,
RE_JSWS varchar(16) DEFAULT ' ' NOT NULL,
PRIMARY KEY (RE_ADID,RE_ADID_SEQ,RE_ADSTAT,RE_ADFROM,RE_ADOPNO)
)
ENGINE INNODB COLLATE=latin1_general_cs;
--
ALTER TABLE BJADRE
ADD CONSTRAINT BJADRE_FRE01
FOREIGN KEY
(
RE_ADID,
RE_ADID_SEQ,
RE_ADSTAT,
RE_ADFROM,
RE_ADOPNO
)
REFERENCES BJADOP
(
OP_ADID,
OP_ADID_SEQ,
OP_ADSTAT,
OP_ADFROM,
OP_ADOPNO
) ON DELETE CASCADE
;
在hbn中没有引用外键名称BJADRE_FRE01 hibernate生成以下名为FK74D139DE74DBF99B的外键
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 18-feb-2016 10.16.35 by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
<class name="com.a.b.tables.Bjadre" table="BJADRE">
<composite-id name="id" class="com.a.b.tables.BjadreId">
<key-property name="reAdid" type="string">
<column name="RE_ADID" length="14" />
</key-property>
<key-property name="reAdidSeq" type="string">
<column name="RE_ADID_SEQ" length="2" />
</key-property>
<key-property name="reAdstat" type="string">
<column name="RE_ADSTAT" length="1" />
</key-property>
<key-property name="reAdfrom" type="string">
<column name="RE_ADFROM" length="6" />
</key-property>
<key-property name="reAdopno" type="big_decimal">
<column name="RE_ADOPNO" precision="22" scale="0" />
</key-property>
</composite-id>
<one-to-one name="bjadop" class="com.a.b.tables.Bjadop" constrained="true"></one-to-one>
<property name="reJsname" type="string">
<column name="RE_JSNAME" length="16" not-null="true" />
</property>
<property name="reReopno" type="big_decimal">
<column name="RE_REOPNO" precision="22" scale="0" not-null="true" />
</property>
<property name="reCompl" type="string">
<column name="RE_COMPL" length="1" not-null="true" />
</property>
<property name="reJobname" type="string">
<column name="RE_JOBNAME" length="40" not-null="true" />
</property>
<property name="reJsws" type="string">
<column name="RE_JSWS" length="16" not-null="true" />
</property>
</class>
</hibernate-mapping>
感谢