gpt4 book ai didi

java - hibernate : Getting error "nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -15"

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:37 26 4
gpt4 key购买 nike

我在使用 native 查询嵌套异常时遇到异常是 org.hibernate.MappingException:没有 JDBC 类型的方言映射:-15

我的代码是

String sqlQuery = "select emp_id, name, address, dept from employee  where dept in ( Select dept  from department  where status=:status)";
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("status", "Active");
Query sqlQuery = entityManager.createNativeQuery(query.toString());
queryParams.forEach(sqlQuery::setParameter);
List queryResults = (List) sqlQuery.getResultList(); // This line is throwing exception

我使用的数据库是:SQLServer 2012。数据库配置是:

spring.datasource.username=testUser
spring.datasource.password=******
spring.datasource.url=jdbc:sqlserver://server:port;databaseName=testDB;
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.hikari.maximum-pool-size=75
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.minimum-idle=10

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.generate_statistics=false
spring.jpa.properties.hibernate.default_batch_fetch_size=100
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

最佳答案

我真的不知道你的员工和部门的 JPA 看起来怎么样,但我看到了您从两个不同的表中选择部门,并且需要一些如何区分这些列的方法。

String sqlQuery = "select emp_id as emp_id  , name as name , address address, dept as dept  from employee  where dept in ( Select dept as dept_department  from department  where status=:status)";

请参阅以下问题.. Spring Data JPA map the native query result to Non-Entity POJO

关于java - hibernate : Getting error "nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -15",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59051539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com