An error occurred when using hhibernate in Java: No dialect mapping for JDBC Type:-1

Source: Internet
Author: User

Today, we encountered an error when using hibernate, using createsqlquery to obtain data.

Query query = getsession (). createsqlquery (string. Format ("select rulestr, rultype from asr_rule where rulcode = '% S'", baserulecode ));
For (Object item: Query. List ()){
...
}

 

Error in query. List (): No dialect mapping for JDBC Type:-1

It indicates that there is no Dialect Corresponding to the JDBC Type.

Running the tracked SQL statement in the database is successful. According to the prompts, rulestr is of the text type and rultype is of the int type. It should not be a problem of rultype, but a problem of rulestr. After searching, find the solution as follows:

1. inherit from mysqldialect and register the text type:

Public class mysqldialectex extends mysqldialect {
Public mysqldialectex (){
Super ();
Registerhibernatetype (types. longvarchar, "text ");
}
}

 

2. In beans. XML, configure the dialect as mysqldialectex.

<Property name = "hibernateproperties">
<Props>
<Prop key = "hibernate. show_ SQL"> false </prop>
<Prop key = "hibernate. dialect"> org. vsem. mysqldialectex </prop>
</Props>
</Property>

 

 

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.