1.用HibernateCallback
Transaction tx = session.beginTransaction();
tx.commit();
tx.rollback();
2.建议你使用单主键,非要用的话要用<composite-id>,查查hibernate手册
Transaction tx = session.beginTransaction();
tx.commit();
tx.rollback();
2.建议你使用单主键,非要用的话要用<composite-id>,查查hibernate手册
http://community.csdn.net/Expert/topic/4454/4454341.xml?temp=.942135
<key-property name="medicareNumber"/>
<key-property name="dependent"/>
</composite-id>
tx.commit(); //提交事物
tx.rollback(); //回滚事务其实,hibernate只是对jdbc做了轻量的封状,最终的实现,还是通过jdbc的事务管理来实现的,不过用户不必了解那么多,使用hibernate提供的接口就可以。
至于,多主建,一般都是用主建类来实现。
--------------------------------------------
public class StudentCourse implements Serializable {
private StudentCoursePK comp_id;
private Float grade;
......
--------------------------------------------
package eqzhou.mis.studentCourse;import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;public class StudentCoursePK implements Serializable {
private String studentId;
private String courseId;
public StudentCoursePK() {
}
public String getCourseId() {
return courseId;
}
public String getStudentId() {
return studentId;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
} public boolean equals(Object other) {
if ( !(other instanceof StudentCoursePK) ) return false;
StudentCoursePK castOther = (StudentCoursePK) other;
return new EqualsBuilder()
.append(this.getStudentId(), castOther.getStudentId())
.append(this.getCourseId(),castOther.getCourseId())
.isEquals();
} public int hashCode() {
return new HashCodeBuilder()
.append(this.getStudentId())
.append(this.getCourseId())
.toHashCode();
}}
---------------------------------------------<class
name="eqzhou.mis.studentCourse.StudentCourse"
table="student_course"
> <composite-id name="comp_id" class="eqzhou.mis.studentCourse.StudentCoursePK">
<key-property
name="studentId"
column="STUDENT_ID"
type="java.lang.String"
length="8"
>
</key-property>
<key-property
name="courseId"
column="COURSE_ID"
type="java.lang.String"
length="3"
>
</key-property>
</composite-id> ............
---------------------------------------------和你问题相关的部分内容,已经铁了出来,你看下。