日期:2014-05-20 浏览次数:20818 次
class 权限{ 教师 js; 课程 kc; }
------解决方案--------------------
session.createSQLQuery("select 课程表.课程名,教师表.姓名/部门 from 课程表,教师表,权限表 where 权限表.课程ID=课程表.课程ID and 权限表.教师ID=教师表.教师ID and 权限表.权限ID=?")
------解决方案--------------------
还不知道你要查什么。。。。。
课程表 Course
配置文件 course.xml
<hibernate-mapping package="com.po">
<class name="Course" table="Course">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" />
<set name="teachers" table="course_teacher" inverse="true">
<key column="id"/>
<many-to-many column="teacherid"
class="Teacher"/>
</set>
</class>
</hibernate-mapping>
Course类
public class Course{
private long id;
private String name;
private Set teachers;
}
教师表 Teacher
配置文件
<hibernate-mapping package="com.po">
<class name="Teacher" table="Teacher">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" />
<set name="courses" table="course_teacher" inverse="true">
<key column="id"/>
<many-to-many column="courseid"
class="Course"/>
</set>
</class>
</hibernate-mapping>
教师类
public class Teacher{
private long id;
private String name;
private Set courses;
}
权限表就不用写配置文件了,对应于配置文件中course_teacher关联表。
通过教师查课程, teacher.getCourses();
通过课程查教师, course.getTeacher();