PostgraSQL 表名/列名区分大小写
-- Table: public.Album
-- DROP TABLE IF EXISTS public."Album";
CREATE TABLE IF NOT EXISTS public."Album"(
"AlbumId" integer NOT NULL,
"Title" character varying(160) COLLATE pg_catalog."default" NOT NULL,
"ArtistId" integer NOT NULL,
CONSTRAINT "PK_Album" PRIMARY KEY ("AlbumId"),
CONSTRAINT "FK_AlbumArtistId" FOREIGN KEY ("ArtistId")
REFERENCES public."Artist" ("ArtistId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Album" OWNER to postgres;
-- Index: IFK_AlbumArtistId
-- DROP INDEX IF EXISTS public."IFK_AlbumArtistId";
CREATE INDEX IF NOT EXISTS "IFK_AlbumArtistId"
ON public."Album" USING btree
("ArtistId" ASC NULLS LAST)
TABLESPACE pg_default;
查询的时候,引擎默认全部转小写,导致查询失败
select * from Album as album order by album."Title";
ERROR: relation "album" does not exist
SQL state: 42P01
pgsql需要通过双引号
select * from "Album" as album order by album."Title";
JPA需要进行Physical Naming
- 增加配置,强制使用注解名称,注解名称增加双引号。
配置:
spring:
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
database-platform: org.hibernate.dialect.PostgreSQLDialect
实体类:
@Entity
@Data
@Table(name = "\"Album\"")
public class Album {
@Id
@Column(name = "\"AlbumId\"")
private Integer albumId;
@Column(name = "\"Title\"", nullable = false)
private String title;
@Column(name = "\"ArtistId\"", nullable = false)
private Integer artistId;
}
约束
数据库设计时,强制要求表名/列名,使用小写字母,下划线分隔
本文由 Ivan Dong 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jun 13, 2023 at 10:15 am