【问题标题】:Hibernate : Getting error "nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -15"Hibernate:出现错误“嵌套异常是 org.hibernate.MappingException:没有 JDBC 类型的方言映射:-15”
【发布时间】: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&lt;String, String&gt; queryParams 替换这个Map&lt;String, Object&gt; queryParams
  • 能否请您提供employeedepartment 表定义,至少是上述查询中使用的列。

标签: java hibernate spring-data-jpa spring-data


【解决方案1】:

我真的不知道你的员工和部门的 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

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 2012-10-10
    • 2021-06-29
    • 2012-02-09
    • 2012-06-17
    • 2018-04-08
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多