No dialect mapping for JDBC type: 1 workaround for text annotations to database in Hibernate

Source: Internet
Author: User
Tags mysql text

hibernate is not supported for the text data type of the database.
Hibernate is good when using the HQL query to include the text Type field. If you use native SQL, which is when querying the text type using the Createsqlquery method, you always get an error:
Org.hibernate.MappingException:No dialect mapping for JDBC type:-1
Atorg.hibernate.dialect.TypeNames.get (typenames.java:56)

There was a problem with the JDBC driver for hibernate with MySQL: the MySQL text type jdbc Resultsetmetadata.getcolumntype returns-1, and Hibernate does not register the type, So the Createsqlquery reported No dialect mapping for Jdbctype:-1.


Workaround:

1, write a class integrated dialect, and then achieve their own support for text

Import Java.sql.Types;   Import Org.hibernate.dialect.MySQL5Dialect;   public class Dialectforinkfish extends Mysql5dialect {public       dialectforinkfish () {           super ();           Registerhibernatetype (Types.longvarchar, 65535, "text");       }   }  

2.

Modify Hibernate config file Hibernate.cfg.xml, put

<property name= "dialect" >org.hibernate.dialect.MySQL5Dialect</property>  
modified to:



No dialect mapping for JDBC type: 1 workaround for text annotations to database in Hibernate

Related Article

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.