1.org.hibernate.MappingException: Unknown entity
错误原因:没有在hibernate.cfg.xml文件中加入 *.hbm.xml造成的,例如没有填写<mapping resource="com/netctoss/entity/Cost.hbm.xml"/>
2.org.hibernate.exception.SQLGrammarException: could not initialize a collection
错误原因:数据库和映射文件没有对上,例如在*.hbm.xml文件中配置实体类属性与数据库字段映射时,<property name="osUserName" type="string" column="os_username" />,这里如果把name和column其中一个属性写错了(少一个字母啊、拼写错误啊),都会报上述错误,所以好好检查这里吧
3.org.hibernate.hql.ast.QuerySyntaxException: is not mapped
错误原因:hql语句中from是实体类而不是表名,这个应该大家都知道,注意大小写,例如String hql="from Emp";实体类为Emp,数据库表名为emp
4.This project is a not MyEclipse Hibenate project assuming hibernate3 capabilites for
原因:使用版本控制的时候,工程根目录下的:.project
解决:项目名上右键--〉myeclipse-->add hibernatecapabilites -->next-->hibernate config file --> existing-->选择现有工程存在的hibernate配置文件--> next --> 不生成factory class--> end
5.提供一个二级缓存配置文件的dtd及xml scheme头信息
<?xml version="1.0"encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"></ehcache>
6.hibernate中配置mysql数据库主键生成策略,其他配置请参考(http://blog.sina.com.cn/s/blog_a7b8ab2801014m0e.html)
<!-- 配置主键属性和字段的关系 -->
<id name="id" type="integer" column="id">
<!-- 用来指明主键的生成方式 , native可以适应多种数据库 increment mysql自动增长策略 sequence oracle自动增长策略 -->
<generator class="native"></generator>
</id>