hibernate学习手记(1)

 

1. java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configu 

出现该问题,是因为时区没有指定,需要在连接字符串上加上 serverTimezone=UTC

最终的链接语句是 jdbc:mysql:///demo-hibernate?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

 

2. org.hibernate.MappingException: Unknown entity: DBModel.Students 

出现该问题,有好几个原因,有些是配置文件的引用问题,如果说我们在cfg.xml中点击hbm.xml能跳转到相应的文件,说明引用没问题。

我出现这个问题是应为hibernate的版本问题,类库用的高版本,代码里面还是用的旧的写法

我一开始是这么写的

 ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

后来看到这篇文章 http://www.imooc.com/wenda/detail/339079 改成了

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).configure().build();

问题就没了

 

3.org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [*.hbm.xml]

这个错误是因为 cfg.xml文件中<mapping  />的配置问题,检查一下是不是有单词拼写错误

 

4.org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : *.hbm.xml : origin(*.hbm.xml)

这个问题比较恶心,原来我配置原件都是放在src下面的 后来看了这篇文章  http://stackoverflow.com/questions/7127608/org-hibernate-mappingnotfoundexception-resource-hbm-xml-not-found 有所感悟,我看了下编译后的文件(traget文件夹下)确实没有hibernate的配置文件,后来加了一个 resources 文件夹,把配置都放到该文件下,再在build path添加一下就好了

 

posted on 2017-05-10 08:15  Jack·J  阅读(478)  评论(1编辑  收藏  举报

导航