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 .
最佳答案
可能是这样的
@Entity
@Table(name = "mwo_main_status")
public class WorkOrderSubStatusDbMapping {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer _id;
@Column(name = "ref_id")
private Integer oid;
private String label;
private String details;
}
关于java - Spring Jpa Hibernate 列未转换为查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61146301/