英文:
Spring Jpa Hibernate Column not translated to query
问题
以下是翻译好的部分:
错误日志:
[6418c947-1] 发生了意外错误(类型=内部服务器错误,状态=500)。
PreparedStatementCallback; 错误的SQL语法 [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]; 嵌套异常是 org.postgresql.util.PSQLException: ERROR: 列 mwo_main_status.oid 不存在 提示: 或许您想引用列 "mwo_main_status._id"。位置: 36
我的ORM:
@Builder
@Data
@Entity
@Table(name = "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、domain、persistence)的Spring Boot应用程序。
在Persistence模块中,我的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'
}
我缺少什么?
如 在实体上使用Lombok的@Data和@Builder 中所述,Lombok在使用JDBC时工作不正常,因此我决定使用 spring-data-jpa
而不是 spring-data-jdbc
。
感谢 Alex Rudenko。
英文:
The JPA do not translate @Column(name="...") inside sql statement
The error log
[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
my 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;
}
I expected that the generated SQL to be:
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
I'm creating a Spring-Boot Application with submodules (web, domain, persistence)
In Persistence module my gradle.build file is
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'
}
What I'm missing?
As said in Using lomboks @Data and @Builder on entity, Lombok do not work proper with jdbc, so I decided to use spring-data-jpa
instead of spring-data-jdbc
.
Thanks Alex Rudenko.
答案1
得分: 0
可能的话,可能是这样的
@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;
}
英文:
Possibly, it could be this
@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语言的经验与见解,让所有开发者获益!
评论