157
技術社區[雲棲]
MySQL錯誤(org.hibernate.MappingException: No Dialect mapping for JDBC type: -4) 解決方案
今天將開發完畢的項目發布到服務器上有,出現如下錯誤:
org.hibernate.MappingException: No Dialect mapping for JDBC type: -4
後經過分析,是因為服務器上的mysql版本較低(為5.1.66),本地開發版本為5.5的則沒有這個問題,下麵直接貼出解決方法:
1、增加Java類
import java.sql.Types; import org.hibernate.Hibernate; import org.hibernate.dialect.MySQL5InnoDBDialect; public class MySQL5InnoDBDialectEx extends MySQL5InnoDBDialect { public MySQL5InnoDBDialectEx() { super(); registerHibernateType(Types.LONGVARCHAR, 65535, "text"); registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(-1, Hibernate.STRING.getName()); registerHibernateType(Types.LONGVARBINARY, Hibernate.BLOB.getName());//這一行解決No Dialect mapping for JDBC type: -4問題 } }注:前麵3行是也是解決數據類型問題的,第四條是解決我們今天所說的 No Dialect mapping for JDBC type: -4 問題。
2、修改hibernate配置文件
<property name="hibernateProperties"> <value> hibernate.dialect=com.dialect.MySQL5InnoDBDialectEx hibernate.show_sql=false hibernate.format_sql=true hibernate.query.substitutions=true 1, false 0 hibernate.jdbc.batch_size=20 hibernate.generate_statistics=true hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider hibernate.cache.provider_configuration_file_resource_path=/ehcache.xml hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory hibernate.connection.autocommit=false </value> </property>注:第一行引用我們自定義擴展的Java類MySQL5InnoDBDialectEx,後麵的配置為其他配置,與本文章所要解決的問題無關。
最後更新:2017-04-03 08:26:25