我尝试使用以下将本机 SQL 查询映射到 POJO@ConstructorResult
类@SqlResultSetMapping
:
@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 [AnomalieMapping]
这是我在 SGBD 中执行 SQL 查询时生成的内容: