This Hibernate error came at me out of the blue while working on FilmSuggestions.com – I innocently added a constraint to one of my Grails domain models, setting the maxSize of one of the fields to 2000. This changed the table schema making the column type TEXT instead of VARCHAR.
The problem came from a native query:
sessionFactory.getCurrentSession().createSQLQuery(mostPopularFilmsSQL).list()
This selects the TEXT column which results in the error (as described here). Setting the dialect didn’t seem to make any difference, so for now I’ve changed the constraint so it’s back to being a VARCHAR.






{ 3 comments… read them below or add one }
A coworker just hit this same problem the other day. The suggestion on the page you cited to use addScalar worked fine for him – it just tells Hibernate that the column is a String type. It’s only a problem with SQL queries, and you don’t show your SQL, but you can select individual columns using HQL (e.g. reporting queries) and I’m pretty sure this isn’t a problem with HQL queries.
Thanks Burt, I meant to add a note saying that I do have other tables with TEXT columns and they work fine when using straight GORM or criteria.
So how do you use addScalar from your domain class? Can you simply use the mapping property?
static mapping = {
columns {
postCode type:’text’
}
}
Note, I’m working with Grails here, and not using custom hibernate mappings – just straight GORM.
Upgrade your MySQL version to 5.0.3 and change TEXT type to VARCHAR(N) N>[0-65535].