用户关注、和用户粉丝该用对象的思想怎么设计实体?映射文件又该怎么配置呢?
public class User{ //.........基本属性 private Set<User> follow;//用户关注 private Set<User> fans;//粉丝列表 //getter and setter }
解决方案
40
<hibernate-mapping> <class name=”bean.Student” table=”students”> <id name=”id” column=”id” type=”long”> <generator class=”increment”></generator> </id> <property name=”name” column=”name” type=”string”></property> <set name=”courses” table=”students_courses” cascade=”save-update”> <key column=”student_id”></key> <many-to-many class=”bean.Course” column=”course_id”></many-to-many> </set> </class> </hibernate-mapping>
20