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>