SORRY,我的贴了两遍,贴重了!我这就试下加个事务!
解决方案 »
- SSH数据库加了字段 要改哪些文件
- 困惑了2天的问题
- Hibernate 问题,在执行Query session.createQuery(hql) 报错误??帮忙看看下
- webwork如何进行字符串比较?
- 用MSSQL+Weblogic8.1+Jbuilder9创建实体EJB的问题????
- 奇怪的编译错误
- LDAP 目录访问的问题?请各位高人帮忙
- eclipse 用lomboz插件与jboss3.0.8-tomcat的整合问题!
- 请问有人在eclipse中使用ant遇到这样的怪问题吗?
- javax.servlet.http.*包需要重新下载安装吗!
- 正在学hibernate+struts做项目,希望哪位大哥能给点实例代码。
- 求组!前途问题!
Hibernate: update course set cou_name=?, cou_dis=? where cou_id=?
Hibernate: insert into course_student_table (stu_id, cou_id) values (?, ?)
这是插入的代码,没有问题,Hibernate: update student set stu_name=?, stu_pwd=? where stu_id=?
Hibernate: update course set cou_name=?, cou_dis=? where cou_id=?
这就是更新的代码:
没有对course_student_table表进行操作.
请高人来指点一两吧!
你仅仅需要记住下面这个直观的规则:所有的双向关联需要有一端被设置为inverse。在一个一对多(one-to-many)关联中 它必须是代表多(many)的那端。而在多对多(many-to-many)关联中,你可以任意选取一端,两端之间并没有差别。
楼主测试一下,把cascade的数据修改一下看看,如何?
<key column="stu_id"></key>
<many-to-many class="org.eimhe.db.Course" column="cou_id"></many-to-many>
</set>
<set name="students" table="course_student_table" cascade="save-update" lazy="false">
<key column="cou_id"></key>
<many-to-many class="org.eimhe.db.Student" column="stu_id"></many-to-many>
</set> cascade="all,delete-orphan" 改为也不行:
Hibernate: update student set stu_name=?, stu_pwd=? where stu_id=?
Hibernate: update course set cou_name=?, cou_dis=? where cou_id=?
Hibernate: update student set stu_name=?, stu_pwd=? where stu_id=?
Hibernate: update course set cou_name=?, cou_dis=? where cou_id=?
Hibernate: update student set stu_name=?, stu_pwd=? where stu_id=?
Hibernate: update student set stu_name=?, stu_pwd=? where stu_id=?
双改两遍也改不了
高人能给个具体怎么配置这两个SET的例子么?
<class name="Student" table="STUDENTS">
<id name="sid" unsaved-value="null">
<generator class="hilo">
<param name="table">pk_table</param>
<param name="column">id_value</param>
</generator>
</id>
<property name="name"/>
<property name="sex"/>
<property name="birthday"/>
<property name="edu"/>
<property name="cardno" unique="true" not-null="true"/>
<set name="courses" table="ENROLLMENTS" inverse="true" cascade="save-update">
<key column="sid"/>
<many-to-many class="Course" column="cid"></many-to-many>
</set>
</class>
<class name="Course" table="COURSES">
<id name="cid" unsaved-value="null">
<generator class="hilo">
<param name="table">pk_table</param>
<param name="column">id_value</param>
</generator>
</id>
<property name="name" unique="true" not-null="true"></property>
<property name="desc"></property>
<set name="students" table="ENROLLMENTS" cascade="save-update">
<key column="cid"></key>
<many-to-many class="Student" column="sid"></many-to-many>
</set>
</class>
</hibernate-mapping>
wangzhiqing(妄想分别执着) tangshuo() 不过,问题还是没有解决.谢谢大家的关心,我打算放弃这多对多的例子.