,
我正在尝试将DockerMySQL与hibernate应用程序结合使用。我的数据库属性是:
hibernate.connection.username=root
hibernate.connection.password=pass
hibernate.hbm2ddl.auto=update
hibernate.connection.url=jdbc:mysql://172.17.0.2:3306/keystone?autoReconnect=true
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
如果使用docker容器ip(172.17.0.2)。
我的休眠配置是:
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">false</property>
<property name="generate_statistics">false</property>
<property name="max_fetch_depth">2</property>
<property name="default_batch_fetch_size">16</property>
<property name="use_streams_for_binary">true</property>
<property name="connection.isolation">2</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">300</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
</session-factory>
我可以使用任何客户端访问docker mysql,但当我尝试从应用程序连接时,我遇到以下错误:
<exception name="Could not open connection">
org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1426)
at org.jpos.ee.DB.beginTransaction(DB.java:168)
at com.bkash.keystone.participant.AbstractParticipant.openDB(AbstractParticipant.java:91)
at com.bkash.keystone.participant.AbstractParticipant.createTrace(AbstractParticipant.java:150)
at com.bkash.keystone.participant.AbstractParticipant.traceDb(AbstractParticipant.java:144)
at com.bkash.keystone.participant.AbstractParticipant.log(AbstractParticipant.java:124)
at com.bkash.keystone.participant.AbstractParticipant.prepare(AbstractParticipant.java:68)
at org.jpos.transaction.TransactionManager.prepare(TransactionManager.java:571)
at org.jpos.transaction.TransactionManager.prepare(TransactionManager.java:637)
at org.jpos.transaction.TransactionManager.run(TransactionManager.java:308)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:689)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:84)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)
... 14 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1418)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682)
... 18 more
</exception>
hibernate无法从mysql连接池获取连接。不知道为什么。
有人能帮忙吗?
1条答案
按热度按时间33qvvth11#
我已经找到了这个问题的解决方法。我使用了下面的命令。
sudo docker run--name keystone-e mysql\u root\u password=pass-e mysql\u database=keystone-dmysql:latest
问题出在哪个安装了mysql verison 8.0.11和身份验证类型“caching\u sha2\u password”。这个答案对我帮助很大。
我用下面的命令创建了容器(mysql:5.7)
sudo docker run--name keystone-e mysql\u root\u password=pass-e mysql\u database=keystone-dmysql:5.7
允许我创建一个标准身份验证类型的用户。
n、 别忘了添加必需的管理角色和模式特权