5

I'm using Spring Boot and PostgreSQL database. I have this entity class:

@Entity
@Table(name = "TEST")

public class Test {
@Id
@GeneratedValue
private Long id;
}

And here's my application.properties file:

spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = 1234
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.dialect = 
org.hibernate.dialect.PostgreSQL94Dialect

It creates table but the name of the table is test (with lowercase). How to make it uppercase?

Here's my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

EDIT

By the way i'm getting the following error while installing the project with Maven (clean,install):

java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171] at .................................... Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented at org.postgresql.Driver.notImplemented(Driver.java:688) ~[postgresql-42.2.4.jar:42.2.4] at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1269) ~[postgresql-42.2.4.jar:42.2.4] ... 70 common frames omitted

Is it somehow related?

3 Answers3

3

You should try following ways:

1) Add to application application.properties spring.jpa.hibernate.naming.physical so:

spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = 1234
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

2) Or try to change org.hibernate.dialect.PostgreSQL94Dialect to org.hibernate.dialect.PostgreSQLDialect

spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = 1234
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

For more information, you should see this or this

Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
  • 1
    First approach didn't work. Maybe i have some mismatch in my pom.xml? Can you check it please i will post it now. – Mukhamedali Zhadigerov Aug 08 '18 at 09:58
  • 1
    Second approach also didn't work. Table still is creating with lowercase. – Mukhamedali Zhadigerov Aug 08 '18 at 10:03
  • Using both and scape my table name solved the error: * spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl * spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect Scape table name (or fields) like this: @Table(name = "\"TEST\"") – David Jesus May 10 '20 at 01:41
0

Try this:

@Table(name = "\"TEST\"")

In postgres:

Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, foo should be equivalent to "FOO" not "foo" according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)

from docs https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html

Piotr Rogowski
  • 3,642
  • 19
  • 24
  • 1
    Please expand your answer with some documentation or explanation, why something works/doesn't work. – hellow Aug 08 '18 at 11:21
0

Try escaping your entity name witha double quotes like following:

@Entity
@Table(name = "\"TEST\"")
public class Test {
   @Id
   @GeneratedValue
   private Long id;
}

Or

@Entity
@Table(name = "TEST")
public class Test implements Serializable {
   @Id
   @GeneratedValue
   private Long id;
}
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24