gpt4 book ai didi

java - 无法在 hibernate 中连接到服务器数据库

转载 作者:行者123 更新时间:2023-12-01 18:10:00 27 4
gpt4 key购买 nike

我可以使用 hibernate 连接到本地数据库,但无法连接到 mysql 远程服务器数据库。我收到此错误:

 Initial SessionFactory creation
failed.org.hibernate.service.spi.ServiceException: Unable to create
requested service
[org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
org.hibernate.service.spi.ServiceException: Unable to create requested
service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
at
org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:261)
at
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
at
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at
org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at
com.axelta.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:31)
at com.axelta.util.HibernateUtil.<clinit>(HibernateUtil.java:15) at
com.axelta.service.AxServiceImpl.getHeartbeatEnabledDevicesList(AxServiceImpl.java:26)
at com.axelta.Scheduler.heartBeatMainService(Scheduler.java:19) at
com.axelta.Scheduler.main(Scheduler.java:38) Caused by:
org.hibernate.HibernateException: Could not instantiate connection
provider [org.hibernate.connection.C3P0ConnectionProvider] at
org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:197)
at
org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:120)
at
org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:55)
at
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105)
at
org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251)
... 15 more Caused by:
org.hibernate.boot.registry.selector.spi.StrategySelectionException:
Unable to resolve name
[org.hibernate.connection.C3P0ConnectionProvider] as strategy
[org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] at
org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:128)
at
org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:194)
... 19 more

最佳答案

    <!-- Database Settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- for org.hibernate.dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<property name="hibernate.connection.isolation">2</property>
<property name = "hibernate.jdbc.batch_size">10 </property>
<mapping class="com.axelta.model.AxDeviceDetails"/>
<mapping class="com.axelta.model.AxAlarm"/>
<mapping class="com.axelta.model.AxAlarmType"/>
<mapping class="com.axelta.model.AxClient"/>
<mapping class="com.axelta.model.AxClientGroup"/>
<mapping class="com.axelta.model.AxDeviceMaster"/>
<mapping class="com.axelta.model.AxNodeAlarm"/>
<mapping class="com.axelta.model.AxNodeAlarmUsers"/>
<mapping class="com.axelta.model.AxNodeDetails"/>
<mapping class="com.axelta.model.AxNodeMetadataDefinition"/>
<mapping class="com.axelta.model.AxRules"/>
<mapping class="com.axelta.model.AxUser"/>
<mapping class="com.axelta.model.HeartBeat"/>
<mapping class="com.axelta.model.Sim"/>

</session-factory>

关于java - 无法在 hibernate 中连接到服务器数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60484257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com