Hibernate各种映射关系总结
2009-10-30 00:00:00 来源:WEB开发网6 Component 映射
component不是实体,没有OID。
1 对象模型
public class Employee
private int id
private String name
private Contact contact
-------------------------------------
public class Contact
private String email
private String address
private String zipcode
private String contactTel
-------------------------------------
public class User
private int id
private String name
private Contact contact
2 mapping文件
Xml代码
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.nintenyun.hibernate">
<class name="User" table="t_user" >
<id name="id" >
<generator class="native"/>
</id>
<property name="name"/>
<component name="contact">
<property name="email"></property>
<property name="address"></property>
<property name="zipcode"></property>
<property name="contactTel"></property>
</component>
</class>
</hibernate-mapping>
7 复合主键mapping
通常将复合主键相关属性,单独放到一个类中
这个类必须实现 Serializable接口
这个类必须重写hashCode()和equals()方法
XML
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.nintenyun.hibernate">
<class name="SC" table="t_sc" >
<composite-id name="scpk">
<key-property name="sno"/>
<key-property name="cno"/>
</composite-id>
<property name="sname"></property>
<property name="cname"></property>
</class>
</hibernate-mapping>
- ››Hibernate高级应用:性能优化策略
- ››hibernate 多对多关系详解(包括中间表,一对多字表...
- ››Hibernate实现mysql数据库limit查询方法
- ››各种SmartPhone上的跨平台开源框架的总结
- ››各种进程保护方法的比较
- ››Hibernate 之父:是时候升级到Java EE 6了
- ››Hibernate查询
- ››Hibernate和iBATIS比较(摘自网络)
- ››Hibernate使用Projections进行聚合操作
- ››hibernate中java.util.Date类型映射
- ››hibernate中update与saveOrUpdate的区别
- ››各种数据库连接java的驱动名和语句
更多精彩
赞助商链接