hibernate(多对多)有关问题
hibernate(多对多)问题。
我在一个视频教程看了一下hibernate的用法,就按照视频上的做法写了一个,唯一不同是就是用数据库,我用的是sqlserver数据,打过sp4补丁。可是当运行到关联表的时候就报错:org.hibernate.exception.SQLGrammarException: could not insert collection: [org.eimhe.Student.teachers#7]
网上我也找了好久,始终不得解决,现将代码提供如下,希望高手指教。
顺便说一下,执行到数据关联关系表的时候数据库端口堵塞,怀疑是session有问题
student表(stuid,stuname)teacher表(teaid,teaname)
stu_tea_table(stuid,teaid)关系表
Student.hbm.xml
<?xml version= "1.0 "?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name= "org.eimhe.Student " table= "student " schema= "dbo " catalog= "test ">
<id name= "stuid " type= "java.lang.Integer ">
<column name= "stuid " />
<generator class= "native " />
</id>
<property name= "stuname " type= "java.lang.String ">
<column name= "stuname " length= "50 " />
</property>
<set name= "teachers " table= "stu_tea_table "
lazy= "false "
cascade= "save-update "
inverse= "false ">
<key column= "stuid "> </key>
<many-to-many class= "org.eimhe.Teacher " column= "teaid "> </many-to-many>
</set>
</class>
</hibernate-mapping>
Teacher.hbm.xml
<?xml version= "1.0 "?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name= "org.eimhe.Teacher " table= "teacher " schema= "dbo " catalog= "test ">
<id name= "teaid " type= "java.lang.Integer ">
我在一个视频教程看了一下hibernate的用法,就按照视频上的做法写了一个,唯一不同是就是用数据库,我用的是sqlserver数据,打过sp4补丁。可是当运行到关联表的时候就报错:org.hibernate.exception.SQLGrammarException: could not insert collection: [org.eimhe.Student.teachers#7]
网上我也找了好久,始终不得解决,现将代码提供如下,希望高手指教。
顺便说一下,执行到数据关联关系表的时候数据库端口堵塞,怀疑是session有问题
student表(stuid,stuname)teacher表(teaid,teaname)
stu_tea_table(stuid,teaid)关系表
Student.hbm.xml
<?xml version= "1.0 "?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name= "org.eimhe.Student " table= "student " schema= "dbo " catalog= "test ">
<id name= "stuid " type= "java.lang.Integer ">
<column name= "stuid " />
<generator class= "native " />
</id>
<property name= "stuname " type= "java.lang.String ">
<column name= "stuname " length= "50 " />
</property>
<set name= "teachers " table= "stu_tea_table "
lazy= "false "
cascade= "save-update "
inverse= "false ">
<key column= "stuid "> </key>
<many-to-many class= "org.eimhe.Teacher " column= "teaid "> </many-to-many>
</set>
</class>
</hibernate-mapping>
Teacher.hbm.xml
<?xml version= "1.0 "?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name= "org.eimhe.Teacher " table= "teacher " schema= "dbo " catalog= "test ">
<id name= "teaid " type= "java.lang.Integer ">