请告知,因为我陷入了JPA中的本机查询之一之间。我在完美执行的oracle查询下面有这个,现在我将它用作JPA的本机查询。
我有分别命名为GFT_GATA,GRODUCT_GTTRIBUTE,GERSON的三个实体类
public static final String GET_PAYMENTS_WITH_DATE = "SELECT * "
+ "FROM "
+ " ( WITH BASE AS "
+ " (SELECT A.*, "
+ " COUNT(*) OVER () AS TOTAL_RECORDS "
+ " FROM "
+ " (SELECT eft.*, "
+ " P.BUSINESS_NAME , "
+ " PA.DESCRIPTION "
+ " FROM GFT_GATA EFT, "
+ " CONTACT_TOKEN CT, "
+ " GRODUCT_GTTRIBUTE PA, "
+ " GERSON P "
+ " WHERE eft.GERSON_id = ? "
+ " AND EFT.TO_CONTACT_TOKEN_ID = CT.CONTACT_TOKEN_ID "
+ " AND EFT.GRODUCT_GTTRIBUTE_ID = PA.GRODUCT_GTTRIBUTE_ID "
+ " AND EFT.GERSON_ID = P.GERSON_ID "
+ " AND EFT.CREATED_ON >= CAST (? AS DATE) "
+ " AND EFT.CREATED_ON <= CAST (? AS DATE) "
+ " ORDER BY eft.created_on "
+ " ) A "
+ " ) "
+ "SELECT ROUND((ROWNUM - MOD(ROWNUM-1, ? )) / ?) +1 PAGE_NUMBER, "
+ " B.* "
+ "FROM BASE B "
+ " ) "
+ "WHERE PAGE_NUMBER = ? ";
现在针对以上查询,我添加了另外两列,分别名为TOTAL_RECORDS和页码,并且添加了相同的EFT ava类,因此我动态地添加了这两列
@Entity
@Table(name="GFT_GATA")
@SqlResultSetMappings({
@SqlResultSetMapping(name="getPayments", entities = {
@EntityResult(entityClass = EftData.class),
@EntityResult(entityClass = GERSON.class),
@EntityResult(entityClass = ProductAttribute.class)
} , classes={
@ConstructorResult(
targetClass=com.fiserv.disbursement.entities.entity.Pagination.class,
columns={
@ColumnResult(name="totalRecords"),
@ColumnResult(name="pageNumber")
}
)
})
})
我创建了同名分页类的pojo,但问题是执行后仍然出现错误。
Javax.persistence.PersistenceException:org.hibernate.HibernateException:无法解析结果集中的列名[totalRecords]