我有一些本地查询,并希望将查询结果映射到非实体POJO类的列表中:
@SqlResultSetMapping(
name = "SomeMapping",
classes = {
@ConstructorResult(targetClass = SomeClass.class,
columns = {
@ColumnResult(name = "id", type = Integer.class),
@ColumnResult(name = "NAME", type = String.class),
@ColumnResult(name = "DATE_BEGIN", type = java.util.Date.class)
}
)
}
)
public class SomeClass{
private Integer id;
private String name;
private java.util.Date begDate;
private java.util.Date endDate;
public SomeClass(Integer id, String name, Date begDate){
this.id = id;
this.name = name;
this.begDate = begDate;
}
//Getters & Setters ...
}
一般我想要检索查询执行的结果:
String query = "SELECT " +
"A.id AS 'id', " +
"A.name AS 'NAME', " +
"A.begDate AS 'DATE_BEGIN' " +
"FROM " +
"SomeTable A " +
"WHERE A.endDate < '2014-01-01'";
List<SomeClass> result = em.createNativeQuery(query, "SomeMapping").getResultList();
但我总是得到对象列表。如何检索我的 POJO 列表?