我正在使用Spring Boot
和PostgreSQL
数据库。我有这个实体类:
@Entity
@Table(name = "TEST")
public class Test {
@Id
@GeneratedValue
private Long id;
}
这是我的application.properties
文件:
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
它创建表,但表的名称为test
(小写)。如何使其大写?
这是我的pom.xml
文件:
<?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>
编辑
用Maven安装项目时,出现以下错误(清理,安装):
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
与之相关吗?
答案 0 :(得分:1)
您应该尝试以下方法:
1)如此添加到应用程序application.properties spring.jpa.hibernate.naming.physical
:
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)或尝试将org.hibernate.dialect.PostgreSQL94Dialect
更改为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
答案 1 :(得分:0)
尝试一下:
@Table(name = "\"TEST\"")
在postgres中:
引用标识符也使其区分大小写,而未引用 名称总是折叠为小写。例如,标识符 PostgreSQL认为FOO,foo和“ foo”相同,但是“ Foo” 和“ FOO”彼此不同。 (折叠 PostgreSQL中无引号的小写字母名称与 SQL标准,该标准指出未加引号的名称应折叠成大写 案件。因此,foo应该等效于“ FOO”而不是“ foo” 标准。如果您想编写可移植的应用程序,那么您就是 建议始终引用一个特定名称,或者永远不要引用它。)
来自文档https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html
答案 2 :(得分:0)
尝试使用双引号将您的实体名称转义,如下所示:
@Entity
@Table(name = "\"TEST\"")
public class Test {
@Id
@GeneratedValue
private Long id;
}
或
@Entity
@Table(name = "TEST")
public class Test implements Serializable {
@Id
@GeneratedValue
private Long id;
}