我有一个具有一对一关系的聚合,并且在第二级中,子实体具有一对多关系(列表)。当前,当实体被保存时,它会执行预期的操作,并且可以正常保存。但是当我尝试从数据库中获取实体时,生成的 SQL 是错误的,从而导致错误。我真的不能告诉我在这里缺少什么,任何帮助将不胜感激。我正在使用 Lombok、spring-data-jdbc 和 spring-boot。也许龙目岛有事可做,但我不知道。Heres代码举例说明我在说什么:界面
public interface ChargeRepository extends CrudRepository<Charge, Long> {
}
实体
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Charge {
@Id
private Long id;
private Double someData;
private Summary summary;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Summary {
@Id
private Long id;
private Double otherData;
private List<Multiplier> details = new ArrayList<>();
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Multiplier {
@Id
private Long id;
private Double detailData;
}
这是 DDL
CREATE TABLE CHARGE(
ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
SOME_DATA DOUBLE(2) NOT NULL,
PRIMARY KEY(ID)
);
CREATE TABLE SUMMARY(
ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
OTHER_DATA DOUBLE(2) NOT NULL,
CHARGE BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(ID)
);
CREATE TABLE Multiplier(
ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
DETAIL_DATA DOUBLE(2) NOT NULL,
SUMMARY BIGINT UNSIGNED NOT NULL,
SUMMARY_KEY INTEGER NOT NULL,
PRIMARY KEY(ID)
);
问题是,当我保存一个新实体时它没问题,但是当我尝试从数据库中获取它时,生成的 sql 会在表之间建立一个连接,其中包含实体中存在的列“详细信息”,但显然它不是桌子。这是我得到的错误
PreparedStatementCallback; 错误的 SQL 语法 [SELECT charge.id AS id, charge.some_data AS some_data, summary.id AS summary_id, summary.other_data AS summary_other_data, summary.details AS summary_details FROM charge LEFT OUTER JOIN summary AS summary ON summary.charge = charge.id WHERE charge.id = ?]; 嵌套异常是 org.h2.jdbc.JdbcSQLException: Column \"SUMMARY.DETAILS\" not found \nColumn \"SUMMARY.DETAILS\" not found; SQL 语句:\nSELECT charge.id AS id,charge.some_data AS some_data,summary.id AS summary_id,summary.other_data AS summary_other_data,summary.details AS summary_details FROM charge LEFT OUTER JOIN summary AS summary ON summary.charge = charge.id哪里charge.id =?
我在这里缺少什么?编辑:忘记添加,如果列表在根聚合中,它工作正常。