Java Hibernate首次登录失败
我将hibernate用于我的移动应用程序,并成功连接到mysql数据库。 但是在第一次登录数据库时,http请求失败。 我到处找,但没有找到答案。 我知道超时后服务器和数据库停止连接,这就是第一个请求失败的原因。 这是我的hibernate.cfg.xml:Java Hibernate首次登录失败,java,mysql,hibernate,Java,Mysql,Hibernate,我将hibernate用于我的移动应用程序,并成功连接到mysql数据库。 但是在第一次登录数据库时,http请求失败。 我到处找,但没有找到答案。 我知道超时后服务器和数据库停止连接,这就是第一个请求失败的原因。 这是我的hibernate.cfg.xml: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Co
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://us-cdbr-iron-east-01.cleardb.net:3306/heroku</property>
<property name="hibernate.connection.username">
bbb
</property>
<property name="hibernate.connection.password">
qqq
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.pool_size">10</property>
<mapping class="com.example.models.TasksEntity"/>
<mapping resource="TasksEntity.hbm.xml"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
编辑:我将c3p0配置添加到hibernate.cfg.xml中,但在第一次连接时仍然出现异常:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">aa</property>
<property name="hibernate.connection.password">bb</property>
<property name="connection.url">jdbc:mysql://us-cdbr-iron-east-01.cleardb.net:3306/heroku</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">100</property>
<mapping class="com.example.models.TasksEntity"/>
<mapping resource="TasksEntity.hbm.xml"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
aa
bb
jdbc:mysql://us-cdbr-iron-east-01.cleardb.net:3306/heroku
org.hibernate.dialogue.mysqldialogue
com.mysql.jdbc.Driver
1.
100
10
10
10
100
HibernateC3P0
连接过期时不会重新连接
希望它能帮助你 嘿,谢谢你的回答。我将c3p0添加到hibernate.cfg.xml中,但现在我得到了以下错误:“由以下原因引起:java.lang.ClassNotFoundException:org.hibernate.connection.ConnectionProvider”我需要做什么?我使用Hibernate4.3.6。
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">aa</property>
<property name="hibernate.connection.password">bb</property>
<property name="connection.url">jdbc:mysql://us-cdbr-iron-east-01.cleardb.net:3306/heroku</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">100</property>
<mapping class="com.example.models.TasksEntity"/>
<mapping resource="TasksEntity.hbm.xml"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>