Hibernate.cfg.xml配置文件配置错误出现的问题

来源:互联网 发布:php连接mssql 编辑:程序博客网 时间:2024/05/18 00:06

1.把配置多对一关系的语句中_和 - 写错误了:正确:<many-to-one name="depart" column="depart_id" />,错误配置:<many-to-one name="depart" column="depart id" />。sql语句中字段可以用_但是不能用!!害得我找这个错误找了一天。

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [cw.ok.hibernate.bean.Employee]

 Caused by:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-id) values ('?????‰', 2)' at line 1

2.配置信息是正确的,但是我把实体类中的id字段的属性的类型设置成String类型了,id应该是int 类型的。private int id ;

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [cw.ok.hibernate.bean.Department]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'bbs.department' doesn't exist

3. 配置map集合的时候不map-key中type=“string” 写成了大写的String;报错!

            <map name="employees">
<key column="depart_id" />
<map-key type="string" column="name" />
<one-to-many class="EmployeeList"/>
 </map>

Caused by: org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(name)]

4.配置hibernate.cfg.xml文件时,若配置的实体xml文件时,两文件名一样,包名是另一个子包;会报错~,程序不知道去父包中,还是子包中的配置文件;

                <mapping resource="cw/ok/hibernate/bean/extend/Department.hbm.xml" />
<mapping resource="cw/ok/hibernate/bean/extend/Employee.hbm.xml" />

                <mapping resource="cw/ok/hibernate/bean/Department.hbm.xml" />
<mapping resource="cw/ok/hibernate/bean/Employee.hbm.xml" />


原创粉丝点击