[英]spring JPA not adding double quotes to H2 select query
我的配置:
spring.datasource.url=jdbc:h2:mem:db;SCHEMA=public;DB_CLOSE_DELAY=-1;
JPA生成以下查询:
select itement0_.id as id1_0_, itement0_.brand as brand2_0_, itement0_._item_id as item3_0_, itement0_.product_group as product_4_0_ from public.item itement0_ where itement0_.item_id=? [42102-200]
炸毁了
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ITEM" not found; SQL statement
据我所知,问题是h2期望公共模式用双引号引起来,因此以下查询在h2控制台中可以正常运行:
select itement0_.id as id1_0_, itement0_.brand as brand2_0_, itement0_._item_id as item3_0_, itement0_.product_group as product_4_0_ from "public".item itement0_ where itement0_.item_id=? [42102-200]
我的实体:
@Getter
@Entity(name = "item")
@Table(name="item", schema = "public")
@AllArgsConstructor
@NoArgsConstructor(force = true)
public class ItemEntity {
@Id
@GeneratedValue(generator="UUID")
private final UUID id;
@NotNull
@Column(unique = true)
private final String itemId;
private final String productGroup;
private final String brand;
}
Flyway创建脚本:
CREATE TABLE IF NOT EXISTS item
(
id uuid,
item_id VARCHAR,
product_group VARCHAR,
brand VARCHAR,
constraint pk_item PRIMARY KEY (id)
);
有人知道一些解决方法吗?
您可以将hibernate.globally_quoted_identifiers参数添加到application.properties:
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.