首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

刚接触Hibernate 运行报错 帮忙看下解决办法

2012-03-09 
刚接触Hibernate 运行报错 帮忙看下错误信息Exception in thread main java.lang.ExceptionInInitialize

刚接触Hibernate 运行报错 帮忙看下
错误信息

Exception in thread "main" java.lang.ExceptionInInitializerError
at csh.Basic.addUser(Basic.java:32)
at csh.Basic.main(Basic.java:23)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1528)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1448)
at csh.HibernateUtil.<clinit>(HibernateUtil.java:15)
... 2 more
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
... 5 more





配置文件
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///test</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">9118</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>

<mapping resource="csh/hibernate/User.hbm.xml"/>


</session-factory>
</hibernate-configuration>

[解决办法]
问题现象:加载Hibernate时出现异常,可以看到异常信息:
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
原因:hibernate.cfg.xml中引用了错误的DTD文件路径“http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd”。
解决方法:替换为正确的DTD路径:“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”。

来自于:http://txf2004.iteye.com/blog/989654

热点排行