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代码
<?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>
- ››Hibernate高级应用:性能优化策略
- ››hibernate 多对多关系详解(包括中间表,一对多字表...
- ››Hibernate实现mysql数据库limit查询方法
- ››各种SmartPhone上的跨平台开源框架的总结
- ››各种进程保护方法的比较
- ››Hibernate 之父:是时候升级到Java EE 6了
- ››Hibernate查询
- ››Hibernate和iBATIS比较(摘自网络)
- ››Hibernate使用Projections进行聚合操作
- ››hibernate中java.util.Date类型映射
- ››hibernate中update与saveOrUpdate的区别
- ››各种数据库连接java的驱动名和语句
更多精彩
赞助商链接