一、<2014-9-28>
在Hibernate.cfg.xml添加数据库连接池配置后报错。
java.lang.ExceptionInInitializerError
......
......
Caused by: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 20; 元素类型为 "session-factory" 的内容必须匹配 "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)"。
代码如下:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3306/jsp</property>
<property name="connection.username">root</property>
<property name="connection.password">1234</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="entity4/Department.hbm.xml" />
<mapping resource="entity4/Employee.hbm.xml" />
<property name="connection.isolation">2</property>
<!-- c3p0连接池设定 -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<!-- 在连接池中所有数据连接的最大数目 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 在连接池中所有数据连接的最小数目 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 设定数据库连接的过期时间,以秒为单位 -->
<property name="hibernate.c3p0.timeout">120</property>
<!-- 定期检查多有连接池中的空闲连接,以秒为单位 -->
<property name="hibernate.c3p0.idle_test_period">3000</property>
</session-factory>
</hibernate-configuration>
错误原因:xml文件配置错误,mapping*必须在property*之后,将位置调整后,错误修复
二、<2014-9-28>
在按教程上说的配置完Hibernate数据库连接池以后,还是报错
java.lang.ExceptionInInitializerError
......
......
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
错误原因:Hibernate4版本不但需要导入一个c3p0-0.9.2.1.jar还需要导入一个hibernate-c3p0-4.1.2.Final.jar