Org.hibernate.MappingException:No dialect mapping for JDBC type: 4

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.