[英]Spring Jpa Hibernate Column not translated to query
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'
}
我錯過了什么?
正如在實體上使用 lomboks @Data 和 @Builder 中所說,Lombok 不適用於 jdbc,所以我決定使用spring-data-jpa
而不是spring-data-jdbc
。
謝謝亞歷克斯魯登科。
可能,可能是這樣
@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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.