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

Hibernate各种映射关系总结

 2009-10-30 00:00:00 来源:WEB开发网   
核心提示: 4 多对多mapping单向(采用第三方表)1 对象模型Role[id-int,name-String]User[id-int,name-String,role-Set]2映射文件Xml代码 <?xmlversion="1.0"?><!DOCTYPEhibe

4 多对多mapping

单向(采用第三方表)

1  对象模型

Role[id-int,name-String]
User[id-int,name-String,role-Set]

2映射文件

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" /> 
   <set name="role" table="t_user_role"> 
   <key column="userid"></key> 
   <many-to-many class="Role" column="roleid" /> 
   </set> 
  </class> 
</hibernate-mapping>

双向:

1 对象模型:

Role[id-int,name-String,user-Set]
User[id-int,name-String,role-Set]

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="Role" table="t_role"> 
   <id name="id"> 
    <generator class="native"/> 
   </id> 
   <property name="name" /> 
   <set name="user" table="t_user_role"> 
   <key column="userid"></key> 
   <many-to-many class="User" column="userid" /> 
   </set> 
  </class> 
</hibernate-mapping> 

上一页  1 2 3 4 5 6 7  下一页

Tags:Hibernate 各种 映射

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