【发布时间】:2018-09-11 13:43:54
【问题描述】:
我尝试使用@SqlResultSetMapping 的@ConstructorResult 将本机SQL 查询映射到POJO 类,如下所示:
@SqlResultSetMapping(
name = "AnomalieMapping",
classes = @ConstructorResult(
targetClass = Anomalie.class,
columns = {
@ColumnResult(name = "anomalieElement", type = String.class),
@ColumnResult(name = "anomalieType", type = String.class),
@ColumnResult(name = "libelle", type = String.class) }))
public class Anomalie {
private ElementAnomalieEnum anomalieElement;
private TypeAnomalieEnum anomalieType;
private String libelle;
public Anomalie() {
super();
}
public Anomalie(final String libelle, final String anomalieElement, final String anomalieType) {
super();
this.libelle = libelle;
this.anomalieElement = ElementAnomalieEnum.valueOf(StringUtils.stripAccents(anomalieElement.toUpperCase()));
this.anomalieType = TypeAnomalieEnum.valueOf(StringUtils.stripAccents(anomalieType.substring(5).toUpperCase()));
}
//Getters and Setters
}
然后为了在创建本地查询时使用声明的结果集映射,我通过它的名称来引用它:
Query query = entityManager.createNativeQuery(sqlQuery, "AnomalieMapping");
return query.getResultList();
但这对我不起作用,我收到以下错误:
org.hibernate.MappingException: 未知的 SqlResultSetMapping [异常映射]
这是我在 SGBD 中执行 SQL 查询时生成的内容:
【问题讨论】:
-
这个注解是否在您的 JPA 提供者处理的类中?
-
@DN1 我该如何检查?
-
只有你知道它是在什么类上指定的,或者那个类是否是一个实体,或者它是否在persistence.xml中指定
-
@hasnae 该问题的解决方案是添加在我的情况下不起作用的
Entity注释。
标签: java hibernate jpa jpa-2.1 sqlresultsetmapping