GCP Cloud SQL hibernate issue

Posted in :

stlplace
Reading Time: < 1 minute

It complains the table does not exist when in the data.sql we were trying to insert some data. Turns out the table did exist but the default table name was lower case, while we were using Upper case both in the data.sql and the java hibernate entity. The fix is to add one line in the application.properties file. Note this is a spring boot app. Also note the data.sql was used to load initial data in spring boot.

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

I found out about it as I first work around the issue by doing something like shown in this article. But I was thinking this was not right. I was able to find out once I connect to the cloud sql db via proxy. Also refer to this stackoverflow discussion. 

DROP TABLE IF EXISTS employee;

CREATE TABLE employee (
  empId VARCHAR(10) NOT NULL,
  empName VARCHAR(100) NOT NULL
);

Also Spring Data

Spring data REST reference: this is by default will be shown in the root of the website.

the key seems to be adding this in pom:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency>

Last but not least, to disable the end points or to show the available ends points for spring boot app, we can use actuator.

management.endpoints.web.exposure.include=mappings

We can show the end points at:

/actuator/mappings

%d bloggers like this: