1.用HibernateCallback
  Transaction tx = session.beginTransaction();
  tx.commit();
  tx.rollback();
2.建议你使用单主键,非要用的话要用<composite-id>,查查hibernate手册

解决方案 »

  1.   

    软件培训,软件开发培训,java培训,java就业培训,java开发培训,中国首家以就业来验证培训的水平和质量的培训机构http://www.itfuture.org
      

  2.   

    见另一贴(100分)
    http://community.csdn.net/Expert/topic/4454/4454341.xml?temp=.942135
      

  3.   

    如果表使用联合主键,你可以映射类的多个属性为标识符属性。 <composite-id>元素接受<key-property> 属性映射和<key-many-to-one>属性映射作为子元素。 <composite-id>
            <key-property name="medicareNumber"/>
            <key-property name="dependent"/>
    </composite-id>
      

  4.   

    Transaction tx = session.beginTransaction();    //开始一个事务
      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>    ............
    ---------------------------------------------和你问题相关的部分内容,已经铁了出来,你看下。
      

  5.   

    其实提供另外的选择,如果你用spring来和hibernate结合,这个问题会得到很容易的解决.
      

  6.   

    联合主键的问题,其实很简单,Hibernate3做了很大改进,很不错。如果你思维严谨,编码很科学,完全可以用 Spring + Hibernate 做产品的开发了。