gpt4 book ai didi

spring - @SqlResultSetMapping 使用导致架构验证问题

转载 作者:行者123 更新时间:2023-12-04 10:37:46 27 4
gpt4 key购买 nike

我必须提取数据用于统计目的。我创建了一个本地查询并使用了 @SqlResultSetMapping将结果集映射到一个对象。
Hibernate 需要将这个类(Elaboration)声明为 @Entity但不是表格,我不想要表格,因为我只需要在需要时动态提取数据。

代码工作正常,但 gitlab 管道在验证期间失败

schemaManagementException: Schema-validation: missing table [elaboration].

到目前为止,我的代码是:

    SqlResultSetMapping(name="ValueMapping",
classes={
@ConstructorResult(
targetClass=Elaboration.class,
columns={
@ColumnResult(name="areadesc", type=String.class),
@ColumnResult(name="subsectordesc", type=String.class),
@ColumnResult(name="eurovalue", type=BigDecimal.class),
@ColumnResult(name="eurotch", type=BigDecimal.class),
}
)
})
@Entity
public class Elaboration{
@Id
private Long id;
private String areadesc;
private String subsectordesc;
private Integer dossiercount;
private BigDecimal eurovalue;
private BigDecimal eurotch;

....

和自定义查询:

        String statisticValueQuery = "select  a.mdescr as areadesc, s.mdescr as subsectordesc, sum(euro_value) as eurovalue, 
sum(euro_value_tch) as eurotch " +
"from dossier d " +
"join dossier_document dd on d.id = dd.dossier_id " +
"join dossier_country dc on d.id = dc.dossier_id " +
"join country c on dc.country_id = c.id " +
"join area a on c.area_id = a.id " +
"join dossier_subsector ds on d.id = ds.dossier_id " +
"join subsector s on ds.subsector_id = s.id " +
"where dd.document_id = :document " +
"and d.submission_date >= :startdate and d.submission_date <= :enddate " +
"group by s.id, a.id;";

public List<Elaboration> getValueElaboration(ElaborationRequestDTO elaborationRequestDTO){

Query resultMapping = em.createNativeQuery(statisticValueQuery, "ValueMapping");
resultMapping.setParameter("startdate", elaborationRequestDTO.getElaborateFromEquals());
resultMapping.setParameter("enddate", elaborationRequestDTO.getElaborateToEquals());
resultMapping.setParameter("document", elaborationRequestDTO.getDocumentIdEquals());
return resultMapping.getResultList();

有没有办法通过验证测试?
谢谢

最佳答案

这是错误的说法。

Hibernate needs to declare this class (Elaboration) as @Entity



你应该把你的 @SqlResultSetMapping以上部分声明 @Entity但它可以是与 Elaboration 无关的其他实体.

@SqlResultSetMapping(name="ValueMapping",
classes={
@ConstructorResult(
targetClass=Elaboration.class,
columns={
@ColumnResult(name="areadesc", type=String.class),
@ColumnResult(name="subsectordesc", type=String.class),
@ColumnResult(name="eurovalue", type=BigDecimal.class),
@ColumnResult(name="eurotch", type=BigDecimal.class),
}
)
})
@Entity
public class SomeEntity {

}

如果 Elaboration不是一个实体,你不应该这样注释它。

关于spring - @SqlResultSetMapping 使用导致架构验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60091526/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com