没有 JDBC 类型的方言映射:-101

Posted

技术标签:

【中文标题】没有 JDBC 类型的方言映射:-101【英文标题】:No Dialect mapping for JDBC type: -101 【发布时间】:2014-06-13 17:45:14 【问题描述】:

这是我的代码:

String q="select * from emp";
Query que  = em.createNativeQuery(q);
it is working fine but for 

String q="select * from dept";

我使用了基于注解的映射。但它会导致这个异常:

Hibernate: select  activity_id,accepted_on,resource_id, updated_date from case_assignment_history
javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: -101
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:311)
    at $Proxy39.getResultList(Unknown Source)
    at com.quintiles.smsw.core.infrastructure.model.impl.AssignmentPersistent.getCaseHistory(AssignmentPersistent.java:2254)
    at com.quintiles.smsw.core.infrastructure.service.AssignmentService.GetCaseHistory(AssignmentService.java:1033)
    at com.quintiles.smsw.infrastructure.service.test.AssignmentServiceTest.testGetCaseHistory(AssignmentServiceTest.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -101
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
    at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:369)
    at org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:559)
    at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:485)
    at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:501)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2211)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
    at org.hibernate.loader.Loader.list(Loader.java:2090)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66)
    ... 33 more

【问题讨论】:

您是否使用persistence.xml 来设置您的数据源?如果是这样,您可能想尝试设置方言,根据您的数据库使用<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />。要查看可用的方言,请访问:link。 这缺少使用的数据库和休眠版本以及您的表架构。 实际上我正在使用persistence.xml,它对所有其他表都很好,但我已经在该表上创建了索引,包括3 col可能是因为它导致了这个错误......如果那我需要做什么?? 【参考方案1】:

如果列类型的表有TIMESTAMP 试试这样:

select cast(CREATED_TIMESTAMP as date) CREATED_TIMESTAMP from dept;

用于所有列类型 TIMESTAMP

【讨论】:

以上是关于没有 JDBC 类型的方言映射:-101的主要内容,如果未能解决你的问题,请参考以下文章

JPA javax.persistence.PersistenceException:org.hibernate.MappingException:没有 JDBC 类型的方言映射:-101

没有 JDBC 类型的方言映射:1111(本机查询)

JPA SQL Server 没有 JDBC 类型的方言映射:-9

Jpa Join 查询与来自两个表的数据,org.hibernate.MappingException:没有 JDBC 类型的方言映射:2002

Hibernate映射数据库中longtext类型属性时报错No Dialect mapping for JDBC type: -1的解决方案

Hibernate 3.2 中没有 LONGVARCHAR 的映射