java-docs-samples
java-docs-samples copied to clipboard
[Bug] JDBC URL connection using db_username instead of db_name for accessing DB
Hey, I am setting up an application on Google Cloud tech stack:
GCP SQL Postgress 15 Spring JPA 3.0.1 Google App Engine
followed the examples on: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java
My configs:
spring:
cloud:
appId: my-app-id
datasource:
hikari:
data-source-properties:
socketFactory: "com.google.cloud.sql.postgres.SocketFactory"
cloudSqlInstance: ${INSTANCE_CONNECTION_NAME}
sslmode: disable
url: jdbc:postgresql://${DB_NAME}/
password: ${DB_PASSWORD}
username: ${DB_USERNAME}
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
gcp:
sql:
database-name: ${DB_NAME}
My app.yaml
runtime: java17
instance_class: F1
env_variables:
SPRING_PROFILES_ACTIVE: "prod"
INSTANCE_CONNECTION_NAME: postgress_connection_name
DB_NAME: db_name_anything
DB_USERNAME: db_user_anything
DB_PASSWORD: "_my_pass"
handlers:
- url: /.*
script: this field is required, but ignored
automatic_scaling:
min_idle_instances: automatic
max_idle_instances: 1
min_pending_latency: automatic
max_pending_latency: 0.030s
max_instances: 1
Error:
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 3D000
2023-09-17 12:43:26 default[v1] 2023-09-17T12:43:26.201Z ERROR 12 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : FATAL: database "db_name_anything" does not exist
2023-09-17 12:43:26 default[v1] 2023-09-17T12:43:26.208Z ERROR 12 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [FATAL: database "db_name_anything" does not exist] [n/a]
I have solved the problem with creating the user as the name of the db, however, this seems like a bug to me.
Thank you!