java - 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
解决方案
推荐阅读
- postgresql - postgresql 在复制服务器上禁用 DELETE
- excel - 如果值不同,则获取颜色
- javascript - 有没有办法在 React 中创建动态状态和 setState
- html - 如何在 CSS 中为图像位置设置动画?
- sql-server - Microsoft SQL Server Management Studio:存储过程助手
- f# - 检查输入的矩阵是否正确
- javascript - 登录时从用户集合中获取用户数据
- java - AsyncTaskLoader 用于加载程序和后台线程在转换为 androidx 时获取 ClassCastException
- http - Golang 和部署服务
- python - Python Regex:使用反斜杠和换行符匹配成绩单中时间戳子字符串的开始和结束