gpt4 book ai didi

java - @SQLResultSetMapping 未找到列问题

转载 作者:行者123 更新时间:2023-12-01 19:20:26 25 4
gpt4 key购买 nike

我有一个这样的查询

                    FROM RUN cr
LEFT JOIN OFFER_SET os ON cr.ID = os.RUN_ID
LEFT JOIN AA aa ON cr.ID = aa.RUN_ID
LEFT JOIN POLICY ex ON cr.ID = ex.RUN_ID
WHERE cr.ID = '1d4101ea2'

并创建了一个映射实体,以便我可以以正确的格式获取结果集。看起来像这样。

@Entity
@SqlResultSetMapping(name="OutcomeDetails",
entities={
@EntityResult(entityClass=OutcomeDetailsEntity.class, fields={
@FieldResult(name="reason", column="REASON_CD"),
@FieldResult(name="status", column="STATUS_CD"),
@FieldResult(name="countered", column="COUNTERED_FLG"),
@FieldResult(name="id", column="ID"),
@FieldResult(name="version", column="VERSION"),
@FieldResult(name="createdD", column="CREATED_D"),
@FieldResult(name="modifiedD", column="MODIFIED_D"),
@FieldResult(name="corrId", column="CORRELATION_ID"),
@FieldResult(name="policyId", column="POLICY_ID"),
@FieldResult(name="modelId", column="MODEL_ID"),
@FieldResult(name="srcId", column="SRC_ID"),
@FieldResult(name="refId", column="REF_ID"),
@FieldResult(name="serviceName", column="SERVICE_NAME"),
@FieldResult(name="policy", column="POLICY"),
@FieldResult(name="policyVersion", column="POLICY_VERSION"),
})
})

当我在 SQL 控制台中运行此查询时,它工作正常。当我通过代码运行它时,出现此错误

由以下原因引起:java.sql.SQLException:未找到列“corrId”。

代码如下所示

        try {
Query q = cdsEntityManager.createNativeQuery("SELECT aa.REASON_CD, os.COUNTERED_FLG, ex.STATUS_CD, cr.* " +
"FROM RUN cr " +
"LEFT JOIN OFFER_SET os ON cr.ID = os.RUN_ID " +
"LEFT JOIN AA aa ON cr.ID = aa.RUN_ID " +
"LEFT JOIN POLICY ex ON cr.ID = ex.RUN_ID " +
"WHERE cr.ID=:id ", OutcomeDetailsEntity.class);
q.setParameter("id",id);
result = q.getResultList();
} catch (Exception exception) {

我环顾四周,虽然人们也遇到过类似的问题,但没有一个解决方案有效。我在这里缺少什么吗?

最佳答案

对于以后遇到此问题的任何人,我需要将 name 属性和 column 属性更改为相同的内容,所以它看起来像这样

@Entity
@SqlResultSetMapping(name="OutcomeDetails",
entities={
@EntityResult(entityClass=OutcomeDetailsEntity.class, fields={
@FieldResult(name="REASON_CD", column="REASON_CD"),
@FieldResult(name="STATUS_CD", column="STATUS_CD"),
@FieldResult(name="COUNTERED_FLG", column="COUNTERED_FLG"),
@FieldResult(name="ID", column="ID"),
@FieldResult(name="VERSION", column="VERSION"),
@FieldResult(name="CREATED_D", column="CREATED_D"),
@FieldResult(name="MODIFIED_D", column="MODIFIED_D"),
@FieldResult(name="CORRELATION_ID", column="CORRELATION_ID"),
@FieldResult(name="POLICY_ID", column="POLICY_ID"),
@FieldResult(name="MODEL_ID", column="MODEL_ID"),
@FieldResult(name="SRC_ID", column="SRC_ID"),
@FieldResult(name="REF_ID", column="REF_ID"),
@FieldResult(name="SERVICE_NAME", column="SERVICE_NAME"),
@FieldResult(name="POLICY", column="POLICY"),
@FieldResult(name="POLICY_VERSION", column="POLICY_VERSION"),
})
})

关于java - @SQLResultSetMapping 未找到列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59362954/

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