gpt4 book ai didi

hibernate - 无法连接到 postgres

转载 作者:行者123 更新时间:2023-11-29 14:19:30 24 4
gpt4 key购买 nike

对于连接URL

postgres://swnstvngfhgcks:s6oqSe93DVkrcEnyJEHStzpfAt@ec2-54-235-170-124.compute-1.amazonaws.com:5432/d3tqm9uep7oufb

我使用以下persistence设置

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="HotelPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect"/>

<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" value="postgres://ec2-54-235-170-124.compute-1.amazonaws.com:5432/d3tqm9uep7oufb"/>
<property name="javax.persistence.jdbc.user" value="swnstvngfhgcks"/>
<property name="javax.persistence.jdbc.password" value="s6oqSe93DVkrcEnyJEHStzpfAt"/>

<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="javax.persistence.schema-generation.create-source" value="script"/>
<property name="javax.persistence.schema-generation.create-script-source"
value="sql/hotel_postgres.sql"/>
</properties>

</persistence-unit>
</persistence>

但我得到以下异常:

Caused by: org.hibernate.HibernateException: Unable to make JDBC Connection [postgres://ec2-54-235-170-124.compute-1.amazonaws.com:5432/d3tqm9uep7oufb]
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:77)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
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.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.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)

我哪里错了

最佳答案

将 javax.persistence.jdbc.url 属性更改为具有 jdbc:postgresql: 前缀,而不仅仅是 postgres:

jdbc:postgresql://ec2-54-235-170-124.compute-1.amazonaws.com:5432/d3tqm9uep7oufb

文档位于 https://jdbc.postgresql.org/documentation/head/connect.html

关于hibernate - 无法连接到 postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34638047/

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