first ,create two tables you want to make the OR mapping.
create table T_PASSPORT
(
ID NUMBER(4) not null primary key,
SERIAL VARCHAR2(30) not null
)
create table T_PERSON
(
ID NUMBER(4) not null primary key,
NAME VARCHAR2(30) not null,
AGE NUMBER(4) not null
)
alter table T_PASSPORT
add constraint FK_ID foreign key (ID)
references T_PERSON (ID) on delete cascade;
and the hbm.xml of these two tables are:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="Reference.TPassport" table="T_PASSPORT" schema="JIL">
<id name="id" type="java.lang.Long">
<column name="ID" precision="4" scale="0" />
<generator class="foreign">
<param name="property">TPerson</param>
</generator>
</id>
<one-to-one name="TPerson" class="Reference.TPerson" constrained="true">
</one-to-one>
<property name="serial" type="java.lang.String">
<column name="SERIAL" length="30" not-null="true" />
</property>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="Reference.TPerson" table="T_PERSON" schema="JIL">
<id name="id" type="java.lang.Long">
<column name="ID" precision="4" scale="0" />
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="NAME" length="30" not-null="true" />
</property>
<property name="age" type="java.lang.Long">
<column name="AGE" precision="4" scale="0" not-null="true" />
</property>
<one-to-one name="passport" class="Reference.TPassport" cascade="all" outer-join="true"></one-to-one>
</class>
</hibernate-mapping>
Test code:
TPerson per = new TPerson();
TPassport passport = new TPassport();
per.setName("haha");
per.setAge(new Long(20));
passport.setSerial("123345");
passport.setTPerson(per);
per.setPassport(passport);
session.save(per);
then output is :
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into JIL.T_PERSON (NAME, AGE, ID) values (?, ?, ?)
Hibernate: insert into JIL.T_PASSPORT (SERIAL, ID) values (?, ?)
分享到:
相关推荐
本程序包含: hibenate 上传图片,二进制数据,大文本,集合映射的多种关系,onetoone,ontomany,manytomany等关系详细代码示例以及注释,全部由本人测试通过,对理解hibernate配置有极大帮助。
Hibernate continues to be the most popular out-of-the-box framework solution for Java Persistence and data/database accessibility techniques and patterns. It is used for e-commerce–based web ...
NULL 博文链接:https://liqita.iteye.com/blog/1497077
<hibernate-mapping> <class name="com.bjsxt.hibernate.User" table="t_user"> <!-- <many-to-one name="group" column="groupid" cascade="all"/> --> <many-to-one name="group" column...
<hibernate-mapping> <class name="org.wllt.www.po.Dept " table="dept " catalog="hibernate"> <set name="emps" inverse ="true" lazy="true" cascade="none" batch-size=...
</hibernate-mapping>and finally the mapping for the OrderLine entity. <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="LazyLoadEagerLoad" ...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.4.1. Generator 5.1.4.2. Hi/lo algorithm 5.1.4.3. UUID algorithm 5.1.4.4. Identity columns and sequences 5.1.4.5. Assigned identifiers 5.1.4.6. ...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器(discriminator) 5.1.7. 版本(version)(可选) 5.1.8. timestamp (可选) 5.1.9. property 5.1.10. 多对一(many-to-...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器(discriminator) 5.1.7. 版本(version)(可选) 5.1.8. timestamp (可选) 5.1.9. property 5.1.10. 多对一(many-to-...
<hibernate-mapping> <class name="com.hibernate.model.SystemClassInfo" table="system_class_info" schema="dbo" catalog="db_school"> <many-to-one name="systemSpecialtyCode" class=...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器(discriminator) 5.1.7. 版本(version)(可选) 5.1.8. timestamp (可选) 5.1.9. property 5.1.10. 多对一(many-to-...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器(discriminator) 5.1.7. 版本(version)(可选) 5.1.8. timestamp (可选) 5.1.9. property 5.1.10. 多对一(many-to-...
(A mapping like this allows you to map extra columns of a many-to-many association table to the composite element class.) 接下来的的例子是从Order到Item的一个多对多的关联关系, 关联属性是 purchaseDate, ...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器(discriminator) 5.1.7. 版本(version)(可选) 5.1.8. timestamp (可选) 5.1.9. property 5.1.10. 多对一(many-to-...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.4.1. Generator 5.1.4.2. 高/低位算法(Hi/Lo Algorithm) 5.1.4.3. UUID算法(UUID Algorithm ) 5.1.4.4. 标识字段和序列(Identity columns and Sequences...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.4.1. Generator 5.1.4.2. 高/低位算法(Hi/Lo Algorithm) 5.1.4.3. UUID算法(UUID Algorithm ) 5.1.4.4. 标识字段和序列(Identity columns and Sequences...
hibernate-mapping 5.1.3. class 5.1.4. id 5.1.4.1. Generator 5.1.4.2. 高/低位算法(Hi/Lo Algorithm) 5.1.4.3. UUID算法(UUID Algorithm ) 5.1.4.4. 标识字段和序列(Identity columns and Sequences...
6.1.2. hibernate-mapping 6.1.3. class 6.1.4. id 6.1.4.1. Generator 6.1.4.2. 高/低位算法(Hi/Lo Algorithm) 6.1.4.3. UUID算法(UUID Algorithm ) 6.1.4.4. 标识字段和序列(Identity columns and ...
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <!— 配置缓存,必须紧跟在class元素...
5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.4.1. Generator 5.1.4.2. 高/低位算法(Hi/Lo Algorithm) 5.1.4.3. UUID算法(UUID Algorithm ) 5.1.4.4. 标识字段和序列(Identity columns and Sequences...