问题记录:
一、id主键生成策略
1)报错mapping映射文件中id生成策略<uuid.string>出问题
2)解决过程:
根据百度上说,hibernate 3.0以上版本已不支持uuid.string的生成策略。hibernate5.0目前有:
和assigned这几种生成策略。
二、关于hibernate启动速度特别慢的问题
解决过程:
1.通过网上查阅资料,说是DTD文件的问题。DTD文件头如果和本地DTD文件不一致,将会联网去官网进行比对,而运行的时间一般都是浪费在这里,所以还是使用本地DTD文件的完整格式比较好。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
从上面的文件头改成下面的文件头:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
结果运行速度确实提高了很多。
2.但因此产生了一个问题,由于本地没有此dtd文件,需要联网获取导致离线状态会报错:
java.lang.ExceptionInInitializerError
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1586)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1520)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1506)
at cn.chan.util.HibernateUtils.<clinit>(HibernateUtils.java:10)
... 22 more
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1576)
3.按道理讲,那将DTD文件放在本地就可以不联网找了。所以又把文件头改为本地有的DTD文件头,但是还是断网就报错。问题没有解决,后续继续跟进,解决好更新blog。
三、引伸知识----DTD文件
DTD是文档类型定义(Document Type Definition)。DTD文件是描述文件结构的文件。