首页 > 解决方案 > Spring JPA Criteria API 本机查询与连接给出 org.springframework.orm.jpa.JpaSystemException

问题描述

我按照这篇文章 - https://thoughts-on-java.org/jpa-native-queries/在我的 Spring Boot 项目中从 db 获取通用对象列表。这是我尝试过的:

Query query = entityManager.createNativeQuery("SELECT t1.*, t2.name FROM t1 LEFT JOIN t2 on t1.t2_id = t2.id WHERE t2.type = 'TYPE'");
List<Object[]> resultList = (List<Object[]>) query.getResultList();

当第二行被执行时,它给出了这个错误:

org.springframework.orm.jpa.JpaSystemException:没有 JDBC 类型的方言映射

有人可以指出我做错了什么吗?

编辑:

当使用相同的设置在单个表上运行查询并将其映射到其实体时,一切正常。

例如:Class1 是表 t1 的 JPA 实体。例如,这很好用。

Query query = entityManager.createNativeQuery(query_string, Class1.class)

为此使用 PostgreSQL。我的 application.properties 文件

spring.datasource.url= jdbc:postgresql://localhost:5432/my_db
spring.datasource.username=user
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database=POSTGRESQL 
spring.datasource.platform=postgres
spring.jpa.show-sql=true 
spring.database.driverClassName=org.postgresql.Driver
spring.jpa.properties.hibernate.jdbc.time_zone = UTC
spring.jpa.properties.hibernate.format_sql=true

标签: javaspring-data-jpacriteria-api

解决方案


推荐阅读