Hibernate SQL QUERY, problem with TEXT data type in mysql

I need to execute a sql query with hibernate (without matching), but I keep getting this error whenever a field has a TEXT data type in MYSQL:

org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 

I do not know what to do, matching is not an option (dynamic tables in the database, so the number of fields is variable).

Here's the code snippet:

 SQLQuery query = session.createSQLQuery(sql); Object[] values = (Object[]) query.uniqueResult(); 

sql is the string containing the query (it works fine with the mysql query engine). If I change the TEXT data type to varchar, it works fine, but that is not an option!

Any clues?

+1
sql mysql hibernate
source share
2 answers

Here the solution is possible:

 package iam.dirty; import java.sql.Types; import org.hibernate.Hibernate; import org.hibernate.dialect.SQLServerDialect; public class DialectForGkoloc extends SQLServerDialect { public DialectForGkoloc() { super(); registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(-1, Hibernate.STRING.getName()); registerHibernateType(Types.LONGVARCHAR, Hibernate.TEXT.getName()); } } 

Change the Hibernate hibernate.cfg.xml configuration file:

 <property name="dialect"> org.hibernate.dialect.SQLServerDialect </property> 

from:

 <property name="dialect"> iam.dirty.DialectForGkoloc </property> 
+1
source share

A quick google (did you try this first?) Suggest addScalar is your friend here.

0
source share

All Articles