现有两个对象Role(int id,Set<Authority> authoritys)和Authority(int id,String name),多对多单向关联
怎样写对authoritys的增、删、改、查语句(hibernate)???
请举例说明,
谢谢。
怎样写对authoritys的增、删、改、查语句(hibernate)???
请举例说明,
谢谢。
解决方案 »
- Jquery提交表单怎么写
- 突然之间就这样了,求解答,我记得我没设置啊?TOMCAT的设置
- unexpected end of subtree 原因是什么
- 求教struts问题
- myeclipse连接池异常,hibernate连接池异常?
- limit的使用?
- html,jsp的简单问题,100分在线求教,请达人帮忙!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 不能正确检测重复帐号???
- 关于hibernate一个奇怪的问题。。急求
- 关于onunload事件
- 只在resin下才出现的问题sendError() forbidden after buffer has committed 头疼中...
- 在线跪求实现方案 系统公告的实时显示
然后掉用save()方法就行了
学校的xml,中间表是school_college,通过ID来关联。
<class name="School">
<id name="schoolId" type="integer">
<generator class="identity"></generator>
</id>
<property name="schoolName" type="string"></property>
<set name="student" cascade="none" lazy="true">
<key>
<column name="schoolId"></column>
</key>
<one-to-many class="Student" />
</set>
<set name="college" cascade="save-update" table="school_college" lazy="false" inverse="false">
<key>
<column name="schoolId"></column>
</key>
<many-to-many class="College" column="collegeId" />
</set>
</class>
学院的xml
<class name="College">
<id name="collegeId">
<generator class="identity"></generator>
</id>
<property name="collegeName"></property>
<set name="school" table="school_college" lazy="false" inverse="false"
cascade="save-update">
<key column="collegeId"></key>
<many-to-many class="School" column="schoolId"></many-to-many>
</set>
<set name="student" cascade="none" lazy="false">
<key>
<column name="collegeId"></column>
</key>
<one-to-many class="Student" />
</set> </class>
学校bean
public class School {
private int schoolId;
private String schoolName;
private Set<College> college;
学院bean
public class College {
private int collegeId;
private String collegeName;
private Set<School> school;
插入的时候先setSchool所有的属性,将学院的信息也要set进去,然后你操作学校就会更改中间表和对应的学院信息
对中间的连接表的操作是不是只能用createSQLQuery()呢?
有没有对对象的操作,来改变中间关联表的数据内容?
然后掉用save()方法就行了
只好写一个createSQLQuery()对关联表直接操作了。