Hibernate:JDBC 类型没有方言映射:101
Hibernate : No Dialect mapping for JDBC type: 101
我在从数据库中选择记录时遇到问题,
查询:
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 但它显示 Hibernate.Timestamp
编译器无法解决。
hibernate.cfg.xml
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
这样试试:
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();
当 select 通过 "getSingleResult()" 从 table 获取单个结果时,我遇到了类似的问题:
BigDecimal result = (BigDecimal)query.getSingleResult();
事实证明,我必须将 select 语句中返回的数字显式转换为数字:
SELECT CAST(SUM(aggregated) as NUMBER) FROM ....
我在从数据库中选择记录时遇到问题,
查询:
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 但它显示 Hibernate.Timestamp
编译器无法解决。
hibernate.cfg.xml
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
这样试试:
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();
当 select 通过 "getSingleResult()" 从 table 获取单个结果时,我遇到了类似的问题:
BigDecimal result = (BigDecimal)query.getSingleResult();
事实证明,我必须将 select 语句中返回的数字显式转换为数字:
SELECT CAST(SUM(aggregated) as NUMBER) FROM ....