Spring Oracle 引导可分页计数查询错误
Spring Boot pageable count query error with Oracle
我在使用 Oracle 的 Spring JPA 时遇到了问题。
首先,我需要制作一个元素列表(可分页),但我只有一个视图来做所有事情。
这就是我需要在 SQL 语句中使用“distinct”子句的原因。客户不给我其他方式获取数据。
class:
@Entity
@IdClass(TRN04MunicipalityIdEntity.class)
@Table(name = "VISTA_EVENTOS_OGP")
@NamedQuery(name = "TRN04MunicipalityEntity.findId",
query = "select distinct e from TRN04MunicipalityEntity e where e.idMunicipio = ?1 and e.idProvincia = ?2"
+ " order by COD_PROV_NORA")
@NamedQuery(name = "TRN04MunicipalityEntity.findAllOf",
query = "select distinct e from TRN04MunicipalityEntity e where COD_MUN_NORA is not null order by COD_PROV_NORA")
public class TRN04MunicipalityEntity {
@Id
@Column(name = "COD_MUN_NORA", precision = 3, scale = 0)
private BigDecimal idMunicipio;
@Id
@Column(name = "COD_PROV_NORA", precision = 3, scale = 0)
private BigDecimal idProvincia;
@Column(name = "MUNICIPIO_ES", length = 50, insertable = false, updatable = false)
@Basic()
private String municipioEs;
@Column(name = "MUNICIPIO_EU", length = 50, insertable = false, updatable = false)
@Basic()
private String municipioEu;
}
当我在“findAllOf”上使用分页时有一些奇怪的东西。
分页查询可以(第1页的情况)
select
*
from
( select
distinct trn04munic0_.COD_MUN_NORA as cod_mun_nora4_0_,
trn04munic0_.COD_PROV_NORA as cod_prov_nora5_0_,
trn04munic0_.MUNICIPIO_ES as municipio_es6_0_,
trn04munic0_.MUNICIPIO_EU as municipio_eu7_0_
from
VISTA_EVENTOS_OGP trn04munic0_
where
COD_MUN_NORA is not null
order by
COD_PROV_NORA )
where
rownum <= ?
但是……计数查询没有意义
select
count(distinct trn04munic0_.COD_MUN_NORA,
trn04munic0_.COD_PROV_NORA) as col_0_0_
from
VISTA_EVENTOS_OGP trn04munic0_
where
COD_MUN_NORA is not null
count函数上有两个元素,简直是无稽之谈
有什么想法吗?
坦克很多
显式指定适当的计数查询
我在使用 Oracle 的 Spring JPA 时遇到了问题。
首先,我需要制作一个元素列表(可分页),但我只有一个视图来做所有事情。
这就是我需要在 SQL 语句中使用“distinct”子句的原因。客户不给我其他方式获取数据。
class:
@Entity
@IdClass(TRN04MunicipalityIdEntity.class)
@Table(name = "VISTA_EVENTOS_OGP")
@NamedQuery(name = "TRN04MunicipalityEntity.findId",
query = "select distinct e from TRN04MunicipalityEntity e where e.idMunicipio = ?1 and e.idProvincia = ?2"
+ " order by COD_PROV_NORA")
@NamedQuery(name = "TRN04MunicipalityEntity.findAllOf",
query = "select distinct e from TRN04MunicipalityEntity e where COD_MUN_NORA is not null order by COD_PROV_NORA")
public class TRN04MunicipalityEntity {
@Id
@Column(name = "COD_MUN_NORA", precision = 3, scale = 0)
private BigDecimal idMunicipio;
@Id
@Column(name = "COD_PROV_NORA", precision = 3, scale = 0)
private BigDecimal idProvincia;
@Column(name = "MUNICIPIO_ES", length = 50, insertable = false, updatable = false)
@Basic()
private String municipioEs;
@Column(name = "MUNICIPIO_EU", length = 50, insertable = false, updatable = false)
@Basic()
private String municipioEu;
}
当我在“findAllOf”上使用分页时有一些奇怪的东西。
分页查询可以(第1页的情况)
select
*
from
( select
distinct trn04munic0_.COD_MUN_NORA as cod_mun_nora4_0_,
trn04munic0_.COD_PROV_NORA as cod_prov_nora5_0_,
trn04munic0_.MUNICIPIO_ES as municipio_es6_0_,
trn04munic0_.MUNICIPIO_EU as municipio_eu7_0_
from
VISTA_EVENTOS_OGP trn04munic0_
where
COD_MUN_NORA is not null
order by
COD_PROV_NORA )
where
rownum <= ?
但是……计数查询没有意义
select
count(distinct trn04munic0_.COD_MUN_NORA,
trn04munic0_.COD_PROV_NORA) as col_0_0_
from
VISTA_EVENTOS_OGP trn04munic0_
where
COD_MUN_NORA is not null
count函数上有两个元素,简直是无稽之谈
有什么想法吗?
坦克很多