【发布时间】:2019-11-26 12:59:25
【问题描述】:
我在使用本机查询时遇到异常嵌套异常是 org.hibernate.MappingException: No Dialect mapping for JDBC type: -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
【问题讨论】:
-
能否请您提供您的休眠配置。你用什么数据库?
-
@SternK:添加了数据库配置,我使用的数据库是:SQLServer 2012
-
department.status使用什么 sql 类型? -
从你的代码 sn-p 它看起来像字符串,你能不能试着用这个
Map<String, String> queryParams替换这个Map<String, Object> queryParams。 -
能否请您提供
employee和department表定义,至少是上述查询中使用的列。
标签: java hibernate spring-data-jpa spring-data