Java 通过删除行来休眠顺序

Java 通过删除行来休眠顺序,java,hibernate,hibernate-mapping,Java,Hibernate,Hibernate Mapping,我在映射文件中定义了一个一对多集合,当我使用order by属性时,集合中的数据将丢失行,具体取决于我使用什么属性进行排序 <hibernate-mapping> <class name="domain.StudentUser" table="student_user" > .... <set name="studentCourseses" inverse="true" order-by="import_date ASC">

我在映射文件中定义了一个一对多集合,当我使用order by属性时,集合中的数据将丢失行,具体取决于我使用什么属性进行排序

<hibernate-mapping>
    <class name="domain.StudentUser" table="student_user" >

....

    <set name="studentCourseses" inverse="true" order-by="import_date ASC">
        <key>
            <column name="student_userid" length="15" not-null="true" />
        </key>
        <one-to-many class="domain.StudentCourses" />
    </set>
</hibernate-mapping>

public StudentUser findById(java.lang.String id) {
    log.debug("getting StudentUser instance with id: " + id);
    try {
        StudentUser instance = (StudentUser) getSession().get(
                "domain.StudentUser", id);
        return instance;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}
这里我使用import_date,但是这个表有大约15个属性,某些属性会导致集合中缺少行,而其他属性则不会。它似乎不是特定于数据类型的,因为我有一个字符串属性的问题,但是另一个字符串属性可以正常工作,所有数据都会在那里。无论使用何种排序属性,丢失的行总是相同的,因此它不是随机行

大多数学生用户的数据丢失,但不是全部。最后丢失的行没有任何异常,这意味着没有空值或类似的内容

到目前为止,我只是删除了orderby属性,以便获得我的应用程序工作属性,但我仍然需要知道为什么会发生这些问题。到目前为止,我还没有在我使用orderby属性的其他集合中注意到这种行为,只有这一个

我使用的是Hibernate 3.5.3,如果有帮助,这里是StudentCourses表的映射文件

<hibernate-mapping>
<class name="domain.StudentCourses" table="student_courses" >
    <id name="id" type="integer">
        <column name="id" />
        <generator class="native" />
    </id>
    <many-to-one name="classLevel" class="domain.ClassLevel" fetch="select">
        <column name="class_level_code" length="2" not-null="true" />
    </many-to-one>
    <many-to-one name="academicTerm" class="domain.AcademicTerm" fetch="select">
        <column name="academic_term_id" not-null="true" />
    </many-to-one>
    <many-to-one name="studentUser" class="domain.StudentUser" fetch="select">
        <column name="student_userid" length="15" not-null="true" />
    </many-to-one>
    <property name="academicYear" type="integer">
        <column name="academic_year" not-null="true" />
    </property>
    <property name="term" type="string">
        <column name="term" length="8" not-null="true" />
    </property>
    <property name="title" type="string">
        <column name="title" length="64" not-null="true" />
    </property>
    <property name="prefix" type="string">
        <column name="prefix" length="8" not-null="true" />
    </property>
    <property name="courseNum" type="string">
        <column name="course_num" length="8" not-null="true" />
    </property>
    <property name="suffix" type="string">
        <column name="suffix" length="8" />
    </property>
    <property name="sectionNum" type="string">
        <column name="section_num" length="8" />
    </property>
    <property name="units" type="double">
        <column name="units" precision="4" not-null="true" unique="true" />
    </property>
    <property name="letterGrade" type="string">
        <column name="letter_grade" length="6" not-null="true" />
    </property>
    <property name="qtrGpa" type="double">
        <column name="qtr_gpa" precision="4" scale="3" not-null="true" />
    </property>
    <property name="cumGpa" type="double">
        <column name="cum_gpa" precision="4" scale="3" not-null="true" />
    </property>
    <property name="importDate" type="timestamp">
        <column name="import_date" length="19" />
    </property>
    <property name="sourceFileName" type="string">
        <column name="source_file_name" length="128" />
    </property>
    <property name="timeStamp" type="timestamp">
        <column name="time_stamp" length="19" not-null="true">
            <comment>on update CURRENT_TIMESTAMP</comment>
        </column>
    </property>
</class>
更新更多信息:

如果我直接查询StudentCourses表CORRECT与从StudentUser映射集中获取StudentCourses数据CORRECT得到的结果不同,那么它们应该匹配

for(StudentCourses course : getStudentService().retrieveStudentByID("861043440").getStudentCourseses()) {  //MISSING DATA
        System.out.println(course +" - "+course.getTerm());
    }

    for(StudentCourses course : (List<StudentCourses>)getStudentService().getStudentCoursesDAO().findByProperty("studentUser.studentUserid", "861043440")) {  //ALL DATA CORRECT
        System.out.println(course +" - "+course.getTerm());
    }

事实证明,这与排序无关,因为调整排序只能解决部分问题,而不是全部问题。问题是我重写了StudentCourses对象的hashCode方法,当从StudentUser对象填充集合时,它会导致冲突。我修好了,现在一切都好了