更新时间:2023-02-14 11:27:20
JPA 提供了一个 SqlResultSetMapping
允许您将从本地查询返回的任何内容映射到实体 或自定义类.
JPA provides an SqlResultSetMapping
that allows you to map whatever returns from your native query into an Entity or a custom class.
EDIT JPA 1.0 不允许映射到非实体类.仅在 JPA 2.1 中,ConstructorResult 已添加到地图返回一个 java 类的值.
EDIT JPA 1.0 does not allow mapping to non-entity classes. Only in JPA 2.1 a ConstructorResult has been added to map return values a java class.
此外,对于 OP 获取计数的问题,定义一个结果集映射就足够了,ColumnResult
Also, for OP's problem with getting count it should be enough to define a result set mapping with a single ColumnResult