Groovy/Grails unable to resolve class – even if the class is in the same package

The Problem

Every now and then I get this annoying problem in GGTS (Grails/Groovy Tool Suite – Version 3.6.2.RELEASE at the time of this writing), where the IDE just complains about how it can’t resolve a class.  The weird thing is that the file that the IDE is complaining about is in the same package as the class that I’m trying to use.  It built before, and the source hadn’t changed – so clearly this should not be happening.

The Fix

Hitting the Clean button on the Eclipse side (Project -> Clean) seems to make the errors go away.

This apparently has been a problem since June 2010 (forum post reference here), so I’m surprised that it is still an issue in the current version.

Migrating an Existing SQLite3 Database to Grails

I’m started a project using Grails, and I wanted a way to get Grails to generate the Domain classes from an existing SQLite database.  The tool I found to do this was the Grails Database Reverse Engineering Plugin.  This takes an existing SQLite database and gives a groovy Domain class file for each database table that exists.

Settings in BuildConfig.groovy

In the plugins section, add the line

runtime ':db-reverse-engineer:0.5'

Settings in Config.groovy

Add this configuration option (in the global scope) and replace the package name with whatever package name you want.

grails.plugin.reveng.packageName = 'com.somepackagename'

Settings in DataSource.groovy

Under environments -> development, set the following:

dataSource {
     dbCreate = ""
     url = "jdbc:sqlite:/path/to/database/file"
     driverClassName = "org.sqlite.JDBC"

Get the SQLite Dialect

Download HibernateSQLite_with_jar.rar and then extract SQLiteDialect.java from the src/main/java/dialect directory to your applications hibernate directory (/grails-app/conf/hibernate). Also:

  1. Change the package name to hibernate
  2. Add import for org.hibernate.type.StringType
  3. Add import for org.hibernate.type.IntegerType
  4. Change all instances of Hibernate.STRING to StringType.INSTANCE
  5. Change all instances of Hibernate.INTEGER to IntegerType.INSTANCE

Add the SQLite JDBC Library to the Project

The SQLite JDBC Library can be downloaded here: https://bitbucket.org/xerial/sqlite-jdbc/downloads/sqlite-jdbc-3.7.2.jar and then place it in the “lib” folder of the project

Add jta-1.1.jar to the Project

This library came with the Grails installation.  Place it in the “lib” folder of the project.

Running the Plugin

Calling the following will generate the files:



I now have one groovy Domain class for each table in the database in my Grails project!


The unique constraints that got written into my Domain classes were wrong.  I had to fix them.  Initially, the unique identifier wrote the name of the database column, but instead that should be changed to the variable name that the Domain class called it.

Also, the hasMany and belongTo relationships are not set by the plugin (at least I did not configure it), although there should be a way to configure it with the plugin.

© 2019 Henry Poon's Blog

Theme by Anders NorénUp ↑