当我尝试运行nativeQuery时,我的Sping Boot 2.7.5应用程序返回了一个错误:
@Query(value = """select import, export from
(select cast(max(sd.value) - min(sd.value) as float8)
from solar_data sd
where sd.device_address = :deviceAddress
and sd.tstamp between :from and now()) as import,
(select cast(max(sd.value) - min(sd.value) as float8)
from solar_data sd
where sd.device_address = :deviceAddress
and sd.tstamp between :from and now ()) as export
""", nativeQuery=true)
fun getMainScreenData(@Param("deviceAddress") deviceAddress:Long, @Param("from")
from:LocalDateTime) : List<Impex>
它返回两个float作为导入和导出。我的结果接口是:
interface Impex {
fun getImport():Float
fun getExport():Float
}
Jpa错误消息为:
org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
org.hibernate.dialect.TypeNames.get(TypeNames.java:71)
org.hibernate.dialect.TypeNames.get(TypeNames.java:103)
org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:741)
我用方言
spring:
jpa:
databasePlatform: org.hibernate.dialect.PostgreSQL10Dialect
我试着在sql中转换为float和float8,但是结果是一样的。我该如何执行这个原生查询?
1条答案
按热度按时间oalqel3c1#
最后我找到了它。问题是,postgresql result包含括号为每个值如下:
这就是为什么Hibernate不能解析它。我必须这样修改sql: