2012-10-20 35 views
0

我在query.list得到以下異常()行:獲取org.hibernate.MappingException:否JDBC類型的方言映射:-4異常?

org.hibernate.MappingException: No Dialect mapping for JDBC type: -4 
    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) 

以下是我的配置文件:

<property name="hibernate.connection.driver_resource">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">mysql</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydatabase</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.default_schema">mydatabase</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> 

當我試圖運行的應用程序到Eclipse IDE,然後這個異常是不是來了,但當我創建應用程序jar和運行,然後只有我得到它。 在此先感謝...

+0

確保您使用正確的方言來使用您正在使用的數據庫。 – Abubakkar

回答

0

得到了解決:

只需更改查詢,我取整的記錄,而不是選擇特定的。 例如從表,然後從表對象中獲取相應的字段(此處爲腳本)值,而不是使用從表中選擇腳本,現在工作正常。

3

有時,數據庫會以奇怪的類型返回不能映射到Hibernate類型的自定義SQL查詢的結果(特別是在使用select下的表達式時)。

您需要查找有問題的查詢併爲其添加明確的轉換。

例如

Object o = session.createSQLQuery("select 2*2").uniqueResult(); 

可能會導致這樣的問題。您可以按如下修正:

Object o = session.createSQLQuery("select cast(2*2 as int)").uniqueResult(); 
+0

現在我越來越org.hibernate.exception.SQLGrammarException:無法執行查詢異常.... 我有MEDIUMBLOB在我的表,所以我應該給什麼? –

相關問題