Hibernate:JDBC类型没有Dialect映射:101

时间:2015-01-20 11:51:53

标签: java sql database hibernate orm

从数据库中选择记录时遇到问题

查询:

 SELECT rownum as id, mm.metric_name, dm.aggregated_value_float,
 dm.created_timestamp, s.type, s.name as subelement_name FROM
 daily_metric dm, subelement s, metric_metadata mm  WHERE
 dm.subelement_id =s.subelement_id AND 
 TRUNC(dm.created_timestamp)='15-JAN-15' AND s.subelement_id =1456376 
 and dm.metric_metadata_id = mm.metric_metadata_id order by 1,2 desc

代码:

Query query = session.createSQLQuery(query);
Object o =  query.uniqueResult();

堆栈跟踪

org.hibernate.MappingException: No Dialect mapping for JDBC type: 101
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:87)
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:118)
    at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:653)
    at org.hibernate.loader.custom.JdbcResultMetadata.getHibernateType(JdbcResultMetadata.java:93)
    at org.hibernate.loader.custom.ScalarResultColumnProcessor.performDiscovery(ScalarResultColumnProcessor.java:62)
    at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:496)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2073)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
    at org.hibernate.loader.Loader.doQuery(Loader.java:909)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
    at org.hibernate.loader.Loader.doList(Loader.java:2551)
    at org.hibernate.loader.Loader.doList(Loader.java:2537)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
    at org.hibernate.loader.Loader.list(Loader.java:2362)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:351)
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1869)
    at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
    at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
    at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:966)

我已经尝试了link但是showign Hibernate.Timestamp无法被编译器重置。

的hibernate.cfg.xml

 <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
  <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

2 个答案:

答案 0 :(得分:5)

试试这样:

Object result = session.createSQLQuery(
        "SELECT " +
        "   rownum as id, " +
        "   mm.metric_name, " +
        "   dm.aggregated_value_float, " +
        "   dm.created_timestamp as dm_timestamp, " +
        "   s.type, " +
        "   s.name as subelement_name " +
        "FROM " +
        "   daily_metric dm, " +
        "   subelement s, " +
        "   metric_metadata mm " +
        "WHERE " +
        "   dm.subelement_id =s.subelement_id AND " +
        "   TRUNC(dm.created_timestamp)='15-JAN-15' AND " +
        "   s.subelement_id =1456376 AND " +
        "   dm.metric_metadata_id = mm.metric_metadata_id " +
        "ORDER BY 1,2 DESC")
.addScalar("dm_timestamp", TimestampType.INSTANCE)
.uniqueResult();

答案 1 :(得分:1)

通过表中的“ getSingleResult()”选择单个结果时,我遇到了类似的问题:

 BigDecimal result = (BigDecimal)query.getSingleResult();

原来,我不得不将选择语句中返回的数字显式转换为数字:

 SELECT CAST(SUM(aggregated) as NUMBER) FROM ....