请教个问题,hibernate中如果Student类跟Course类是这样的关系:
class Student
{
    Set<Course>  goodCourseSet;
    Set<Course>  badCourseSet;
}
这时hbm中的一对多关系该怎么写啊?谢谢!

解决方案 »

  1.   


      </many-to-one>
      <many-to-one class="eai.module.basicsettings.entity.BsProduct" fetch="select" name="bsProduct">
       <column name="productId" />
    ???
      

  2.   

    楼上是不是回错了?
    我的问题重点在于一个Student对应了两个Course集,如果只是对应一个Course集,写hbm文件是很简单的,在底层数据库表Course里面加一列StudentID属性就可以了,但现在Student对应了两个Course集,仅仅加一列StudentID属性肯定已经区分不出来到底对应哪个Course集了,所以底层表结构要变,这样hbm文件肯定也要变,但我不知该怎么变
      

  3.   

    <set name="goodCourseSet"  cascade="save-update" >
    <key column="student_id"/>
    <many-to-many class="Course"/>
    </set>
      

  4.   

    下面是我猜想出来的一种写法,由于需要区分出某Student的Course是good还是bad,需要在Course表中增加两个字段,student_id和isGood,isGood的值就是用来区分不同CourseSet的,我下面写的只是表示个大概意思,不知道正确的写法是什么样的,请大侠指教!谢谢!
    <set   name= "goodCourseSet"   >  
                    <key >  
                                    <column   name= "student_id"   />  
                                    <column   name= "isGood" value="1"  />  
                    </key>  
                    <one-to-many   class= "Course"/>  
    </set>  
    <set   name= "goodCourseSet"   >  
                    <key >  
                                    <column   name= "student_id"   />  
                                    <column   name= "isGood" value="0"  />   
                    </key>  
                    <one-to-many   class= "Course"/>  
    </set> 
      

  5.   

    大哥,怎么不用Annotation呢?@Entity
    class Student
    {
     private  List<Course> goodCourses;
     private List<Course> badCourses;@OneToMany
     public getGoodCourses()
    {
     return goodCourese
    }
    }
      

  6.   

    给你个链接
    http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entityBTW,我了解过一些Hibernate~
      

  7.   

     <set name="memberFoodInfos" inverse="true">
                <key>
                    <column name="ft_id" />
                </key>
                <one-to-many class="com.list.pojo.MemberFoodInfo" />
            </set>这是个例子 自己对照看一下