Search code examples
hibernategrailsgrails-orm

grails custom GORM dialect prevent 'grails shell' to work - classpath mystery


i'm using Grails 2.3.11.

My domain classes use UUIDs as identifiers stored as binary(16) in MySQL. I have used a very simple custom dialect for Hibernate, and placed it in src/java:

class CustomMysqlDialect extends MySQL5InnoDBDialect {
  public CustomMysqlDialect() {
    super();
    registerColumnType(Types.BINARY,"binary(16)");
  }
}

Then in domain classes i can just use

static mapping = {
    id generator: 'uuid2',sqlType:'BINARY(16)'
...
}

All this work fine, except the grails shell command:

± |binary-uuid ✗| → grails shell
| Packaging Grails application.....
| Error Error executing script Shell: 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'transactionManagerPostProcessor': Initialization of bean failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean 
property 'sessionFactory'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'sessionFactory': Invocation of init method failed; nested exception is 
org.hibernate.HibernateException: Could not instantiate dialect class (Use --stacktrace to see 
the full trace)

Just like the classes in src/java wouldn't get added to the classpath.

The grails console works just fine, and i can easily query/create/update my domain classes, but i really miss the interactivity of the shell...

I tried to put the class in grails-app/utils as well, but it doesn't change anything...

Any idea ?


Solution

  • This worked fine for me. Does it help if you run grails clean and grails compile before starting the shell? Also try adding --verbose --stacktrace to the compile and shell commands - you might be missing a warning or error message:

    $ grails clean
    $ grails compile --verbose --stacktrace
    $ grails shell --verbose --stacktrace
    

    Note that grails-app/utils is misleadingly named. It's not for utility classes, it's for Codecs. Put all Groovy and Java code that not a grails-app artifact (controller, service, codec, etc.) in src/groovy and src/java.