【发布时间】:2020-07-23 13:22:23
【问题描述】:
JPA 不会在 sql 语句中翻译 @Column(name="...") 错误日志
[6418c947-1] There was an unexpected error (type=Internal Server Error, status=500).
PreparedStatementCallback; bad SQL grammar [SELECT mwo_main_status._id AS _id, mwo_main_status.oid AS oid, mwo_main_status.label AS label, mwo_main_status.details AS details FROM mwo_main_status]; nested exception is org.postgresql.util.PSQLException: ERROR: column mwo_main_status.oid does not exist Dica: Perhaps you meant to reference the column "mwo_main_status._id". Posição: 36
我的 ORM
@Builder
@Data
@Entity
@Table("mwo_sub_status")
public class WorkOrderSubStatusDbMapping {
@GeneratedValue(strategy= GenerationType.IDENTITY)
private @Id Integer _id;
@Column(name="ref_id")
private Integer oid;
private String label;
private String details;
}
我希望生成的 SQL 是:
SELECT mwo_main_status._id AS _id, mwo_main_status.ref_id AS oid, mwo_main_status.label AS label, mwo_main_status.details AS details FROM mwo_main_status
我正在创建一个带有子模块(Web、域、持久性)的 Spring-Boot 应用程序
在持久性模块中,我的 gradle.build 文件是
apply plugin: 'java-library'
dependencies {
implementation project(':domain')
implementation 'io.projectreactor:reactor-core:3.3.3.RELEASE'
implementation 'org.springframework:spring-context:5.2.4.RELEASE'
implementation 'org.springframework:spring-orm:5.2.4.RELEASE'
implementation 'org.springframework.data:spring-data-jdbc:1.1.5.RELEASE'
implementation 'org.hibernate:hibernate-core:5.4.11.Final'
runtimeOnly('org.postgresql:postgresql')
runtimeOnly('org.postgresql:postgresql')
testImplementation 'junit:junit:4.12'
}
我错过了什么?
正如Using lomboks @Data and @Builder on entity 中所说,Lombok 不适用于 jdbc,因此我决定使用 spring-data-jpa 而不是 spring-data-jdbc。
谢谢Alex Rudenko。
【问题讨论】:
-
在 WorkOrderSubStatusDbMapping.class 中使用@Entity 注解
-
其他注释有用吗?您是否也在项目中使用 xml 进行持久性配置?