请注意标签<query>要定义在<class>之外<hibernate-mapping>之内
如果定义在<class>之内,就有可能报这个错误
<
hibernate-mapping
>
< class table ="class" name ="cn.hxex.exam.model.Classes" >
< id name ="id" column ="id" >
< generator class ="uuid.hex" ></ generator >
</ id >
< property name ="title" column ="title" />
< set name ="teachers" table ="teacher_class" inverse ="true" lazy ="true" cascade ="all" >
< key column ="class_id" ></ key >
< many-to-many class ="cn.hxex.exam.model.Teacher" column ="teacher_id" ></ many-to-many >
</ set >
< set name ="students" inverse ="true" >
< key column ="class_id" ></ key >
< one-to-many class ="cn.hxex.exam.model.Student" ></ one-to-many >
</ set >
</ class >
************************************************************************
******************注意<query>标签位置*******************************
************************************************************************
< query name ="getTeacherNotInClasses" >
<![CDATA[ from Classes where id not in (select t.classes.id from Teacher t where t.id=:teacherid) ]]>
</ query >
< query name ="getClassesByTitle" > <![CDATA[ from Classes where title=:title ]]> </ query >
</ hibernate-mapping >
< class table ="class" name ="cn.hxex.exam.model.Classes" >
< id name ="id" column ="id" >
< generator class ="uuid.hex" ></ generator >
</ id >
< property name ="title" column ="title" />
< set name ="teachers" table ="teacher_class" inverse ="true" lazy ="true" cascade ="all" >
< key column ="class_id" ></ key >
< many-to-many class ="cn.hxex.exam.model.Teacher" column ="teacher_id" ></ many-to-many >
</ set >
< set name ="students" inverse ="true" >
< key column ="class_id" ></ key >
< one-to-many class ="cn.hxex.exam.model.Student" ></ one-to-many >
</ set >
</ class >
************************************************************************
******************注意<query>标签位置*******************************
************************************************************************
< query name ="getTeacherNotInClasses" >
<![CDATA[ from Classes where id not in (select t.classes.id from Teacher t where t.id=:teacherid) ]]>
</ query >
< query name ="getClassesByTitle" > <![CDATA[ from Classes where title=:title ]]> </ query >
</ hibernate-mapping >