在 EclipseLink 2.5 (JPA 2.1) 中,我试图将本机查询的结果映射到 POJO,根据这些链接应该是可能的:
- JPA:如何将原生查询结果集转换为 POJO 类集合
- http://www.eclipse.org/eclipselink/api/2.5/javax/persistence/ConstructorResult.html
...使用这种语法(直接取自 EclipseLink 2.5 api 文档):
Query q = em.createNativeQuery(
"SELECT c.id, c.name, COUNT(o) as orderCount, AVG(o.price) AS avgOrder " +
"FROM Customer c, Orders o " +
"WHERE o.cid = c.id " +
"GROUP BY c.id, c.name",
"CustomerDetailsResult");
@SqlResultSetMapping(
name="CustomerDetailsResult",
classes={
@ConstructorResult(
targetClass=com.acme.CustomerDetails.class,
columns={
@ColumnResult(name="id"),
@ColumnResult(name="name"),
@ColumnResult(name="orderCount"),
@ColumnResult(name="avgOrder", type=Double.class)
}
)
}
)
但是,找不到@SqlResultSetMapping 的“类”属性。我尝试使用 Eclipselink 2.5.2 和 2.6。我必须使用另一个(可选)EclipseLink jar 来获得该功能吗?