在网上看的大家都在说不用引入c3p0-0.9.2.1.jar或者只引入c3p0-0.9.2.1.jar。我的无论引用或者不引用项目启动时都是500.而且提示的错误居然说是你的回话工厂类不存在。由于是刚配置了C3PO才出的问题,所以目标很明确是配置错误。后来将mchange-commons-java-0.2.3.4.jar这个包导入项目居然能运行了。所以总结下需要引入c3p0-0.9.2.1.jar和mchange-commons-java-0.2.3.4.jar;由于初学C3PO也不是很懂。下面贴配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 数据库驱动 -->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- 数据库连接的URL -->
<property name="connection.url">
jdbc:mysql://localhost:3306/miss
</property>
<!-- 数据库连接用户名 -->
<property name="connection.username">root</property>
<!-- 数据库连接密码 -->
<property name="connection.password">1111</property>
<!-- Hibernate方言 -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- 打印SQL语句 -->
<property name="show_sql">true</property>
<property name="myeclipse.connection.profile">mysql</property>
<!-- =============== C3P0连接池设定 =================== -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">2</property>
<property name="c3p0.idleConnectionTestPeriod ">18000</property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="c3p0.maxIdleTime">3000</property>
<property name="c3p0.testConnectionOnCheckout">true</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout">2000</property>
<!-- 下面这句很重要,防止8小时自动断开 -->
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<!-- 映射文件 -->
<mapping resource="model/Student.hbm.xml" />
<mapping resource="model/Manager.hbm.xml" />
<mapping resource="model/Teacher.hbm.xml" />
<mapping resource="model/Document.hbm.xml" />
<mapping resource="model/News.hbm.xml" />
<mapping resource="model/Picture.hbm.xml" />
<mapping resource="model/SimpleNews.hbm.xml" />
<mapping resource="model/Course.hbm.xml" />
<mapping resource="model/StudentCourse.hbm.xml" />
<mapping resource="model/Sc.hbm.xml" />
<mapping resource="model/TeacherForCourse.hbm.xml" />
<mapping resource="model/StudentForCourse.hbm.xml" />
<mapping resource="model/CourseForStudent.hbm.xml" />
</session-factory>
</hibernate-configuration>