<id name="stuId" type="java.lang.Integer" unsaved-value="0">
            <column name="stu_id" />
            <generator class="native" />
        </id>
有必要吗? 映射表出了两个stuId   Getter时肯定有突出.有了多对一的关系.主表就不要再设主键了.

解决方案 »

  1.   

    <class name="org.libo.db.Student" table="student">
    <set name="courses" table="course_student_table" cascade="save-update" inverse="false" lazy="false">
            <key column="stu_id"></key>
            <many-to-many class="org.libo.db.Student" column="cou_id"></many-to-many>
            </set>
    怎么影射的啊? 
    <set name="courses" table="course_student_table" cascade="save-update" inverse="false" lazy="false">
            <key column="stu_id"></key>
            <many-to-many class="org.libo.db.Course" column="cou_id"></many-to-many>
            </set>
      

  2.   

    <set name="courses" table="class_course" cascade="persist">
          <key column="classid" />
          <many-to-many class="Course" column="courseid" foreign-key="fk_course"/>
        </set><set name="classes" table="class_course" inverse="true">
          <key column="courseid" />
          <many-to-many class="Class" column="classid" foreign-key="fk_class"/>
        </set>
      

  3.   

    兄弟,跟你类似的问题,多对多,主键由序列Sequence生成,但取主键的时候貌似出了问题:09:30:19,660 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: org.domain.jbossseamtmsoa.entity.Role, getter method of property: roleid
    09:30:19,661 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
    org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.domain.jbossseamtmsoa.entity.Role.roleid
    ....
    Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
    ... 103 more
    09:30:19,668 SEVERE [application] javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.domain.jbossseamtmsoa.entity.Role.roleid
    javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.domain.jbossseamtmsoa.entity.Role.roleid
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:387)
    ....