WEB开发网
开发学院软件开发Java Hibernate各种映射关系总结 阅读

Hibernate各种映射关系总结

 2009-10-30 00:00:00 来源:WEB开发网   
核心提示: 6 Component 映射component不是实体,没有OID,Hibernate各种映射关系总结(7),1 对象模型publicclassEmployeeprivateintidprivateStringnameprivateContactcontact-publicclassContac

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>

上一页  2 3 4 5 6 7 

Tags:Hibernate 各种 映射

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接