If there is no problem with using hql statements, there will be a problem through SQL. The reason is that the SQL query field contains the field type such as mediumtext. If an error is reported, an error will be reported in ejb SQL. Just change it to the varchar type.
Error Exception:
Org. hibernate. MappingException: No Dialect mapping for JDBC type:-1
At org. hibernate. dialect. TypeNames. get (TypeNames. java: 56)
At org. hibernate. dialect. TypeNames. get (TypeNames. java: 81)
Cause: a text field exists in the Database Table, and Hibernate does not register this field in the native query. Therefore, this error occurs.
Solution: Write a class and modify the hibernate configuration file. Write a subclass of Dialect. Here I use the extends MySQL5Dialect class:
Package xxx. xxx; // xxx. xxx write import java. SQL. Types as needed;
Import org. hibernate. dialect. MySQL5Dialect;
Public class DialectForInkfish extends MySQL5Dialect {
Public DialectForInkfish (){
Super ();
RegisterHibernateType (Types. LONGVARCHAR, 65535, "text ");
}
}
Modify the Hibernate configuration file hibernate. cfg. xml
<Property name = "dialect"> org. hibernate. dialect. MySQL5Dialect </property>
To:
<Property name = "dialect"> com. ibm. crl. inkfish. config. DialectForInkfish </property>
Hibernate ntext:
1. First Use FrontEnd Plus to decompile SQLServerDialect. It is found that SQLServerDialect inherits SybaseDialect and Dialect has the registerHibernateType method. Then, check that the registerColumnType in SybaseDialect structure is not registered with.
This step makes it clear that dialect in Hibernate. cfg. xml does not register the ntext type. Well, register one yourself.
2. Define MySQLServerDialect
MySQLServerDialect
3. Use MySQLServerDialect in hibernate. cfg. xml
Run the program again. Everything is OK.
Link: http://itlife365.com/blog/read.php/472.htm