hibernate对应关系配置

一对多配置:
view plaincopy to clipboardprint?
<hibernate-mapping>

<class name="com.shareinfo.model.Peruserinfo"
table="Peruserinfo">
<!--hibernate为我们生成主键id-->
<id name="userid" type="long">
<generator class="sequence">
<param name="sequence">peruserinfo_userid</param>
</generator>
</id>
<property name="username"/>
<property name="password"/>
<set name="books" lazy="true" inverse="true" cascade="all" >
<key column="peruserid"/> //这个是Book表的外键(book外的一个字段)
<one-to-many class="com.shareinfo.model.Bookinfo"/>
</set>
</class>

</hibernate-mapping>


多对多配置:
view plaincopy to clipboardprint?
<set
name="courses"
table="Student_Course_Link" //中间表
lazy="false"
inverse="false"
cascade="all"
sort="unsorted"
>
<key
column="StudentId" // Student_Course_Link的StudentId
/>
<many-to-many
class="com.hellking.study.hibernate.Course"
column="CourseId"
// Student_Course_Link中的CourseId(意思就是用这个CourseId关联Course的主键)
outer-join="auto"
/>


多对一的配置:(学生映射表可以这样配置)
view plaincopy to clipboardprint?
<many-to-one
name="classes"
class="com.hellking.study.hibernate.Classes"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ClassesId" //当前表的ClassesId />


一对一的配置:

view plaincopy to clipboardprint?
<one-to-one
name="address"
class="com.hellking.study.hibernate.Address"
cascade="none"
outer-join="auto"
constrained="false"
/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值