jpa postgresql没有JDBC类型的方言Map:1111

ao218c7q  于 2022-12-26  发布在  PostgreSQL
关注(0)|答案(1)|浏览(303)

当我尝试运行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,但是结果是一样的。我该如何执行这个原生查询?

oalqel3c

oalqel3c1#

最后我找到了它。问题是,postgresql result包含括号为每个值如下:

(3764.81494140625),(2461.824951171875)

这就是为什么Hibernate不能解析它。我必须这样修改sql:

select ri.val as import,
       re.val as export
from
    (select max(sd.value) - min(sd.value) as val
     from solar_data sd
     where sd.device_address=:deviceAddress
           and sd.tstamp between :f and now ()
    ) ri ,
    (select max(sd.value) - min(sd.value) as val
     from solar_data sd
     where sd.device_address=:deviceAddress
           and sd.code_id= (select id from codes where code= '1-0:1.8.0')
           and sd.tstamp between :f and now ()
    ) re

相关问题