我尝试创建本机查询,该查询支持在spring jpa中对视图进行分页。但是似乎ORDER BY引起了一些视图问题。请帮助我解决此问题
@Query(nativeQuery = true, value = "SELECT mvno_id , tac, imsi, manufacturer, model_name, is_active, created_time, last_modified_time FROM "
+ "(SELECT A.mvno_id mvno_id, B.tac tac, A.imsi imsi, B.manufacturer manufacturer , B.model_name model_name, "
+ "A.is_active is_active, A.created_time created_time, A.last_modified_time last_modified_time"
+ " FROM device_repo.device_info A "
+ "INNER JOIN device_repo.device_pack B ON A.imei = B.tac and B.model_name = ?1) "
+ "device_view ORDER BY ?#{#pageable}",
countQuery = "SELECT count(*) FROM device_view")
public Page<DevicePackEntityView> findByModelName(String model, Pageable pageable);
但是我低于例外
org.postgresql.util.PSQLException: ERROR: missing FROM-clause entry for table "a"
Position: 448
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
动态形成的sql查询是
SELECT
mvno_id ,
tac,
imsi,
manufacturer,
model_name,
is_active,
created_time,
last_modified_time
FROM
(SELECT
A.mvno_id mvno_id,
B.tac tac,
A.imsi imsi,
B.manufacturer manufacturer ,
B.model_name model_name,
A.is_active is_active,
A.created_time created_time,
A.last_modified_time last_modified_time
FROM
device_repo.device_info A
INNER JOIN
device_repo.device_pack B
ON A.imei = B.tac
and B.model_name = ?) device_view
ORDER BY
?,
A.manufacturer asc limit ?