Stacktracesorg.hibernate.MappingException:No dialect mapping for JDBC type: 4 Org.hibernate.dialect.TypeNames.get (typenames.java:56) Org.hibernate.dialect.TypeNames.get (Typenames.java : Bayi) org.hibernate.dialect.Dialect.getHibernateTypeName (dialect.java:370) Org.hibernate.loader.custom.customloader$metadata.gethibernatetype (customloader.java:559) Org.hibernate.loader.custom.customloader$scalarresultcolumnprocessor.performdiscovery (CustomLoader.java:485) org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes (customloader.java:501) Org.hibernate.loader.Loader.getResultSet (loader.java:1796) org.hibernate.loader.Loader.doQuery (Loader.java : 674)
Problem Restore:
Database is MySQL, read the table in a blog type field
String hql = "Select id,img from Test"; Session session = GetSession (); list = Session.createsqlquery (HQL). List ();
Problem solving:
This is because MySQL (blob or text) is not registered for this type in hibernate
Rewrite MySQL dialect, create a new class
Import Java.sql.types;import Org.hibernate.hibernate;import Org.hibernate.dialect.mysqldialect;public class Blobmysqldialect extends Mysqldialect{public blobmysqldialect () { super (); Registerhibernatetype (Types.longvarbinary, Hibernate.BLOB.getName ());} }
Modify Hibernate configuration file
<property name= "dialect" >org.hibernate.dialect.MySQLDialect</property> modified to: <property Name= "dialect" > The path of the class/blobmysqldialect</property>
Itmyhome
Org.hibernate.MappingException:No dialect mapping for JDBC type:-4