hibernate - grails自定义GORM方言阻止 'grails shell'起作用-类路径之谜

标签 hibernate grails gorm

我正在使用Grails 2.3.11。

我的域类使用UUID作为在MySQL中存储为binary(16)的标识符。我为Hibernate使用了一个非常简单的自定义方言,并将其放在src / java中:

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

然后在 Realm 类中,我只能使用
static mapping = {
    id generator: 'uuid2',sqlType:'BINARY(16)'
...
}

除了grails shell命令,所有这些工作正常:
± |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)

就像src / java中的类不会添加到类路径中一样。

grails控制台工作正常,我可以轻松查询/创建/更新域类,但是我真的很想念shell的交互性...

我也尝试将类放在grails-app / utils中,但是它没有任何改变...

任何的想法 ?

最佳答案

这对我来说很好。如果在启动 shell 程序之前运行grails cleangrails compile,是否有帮助?另外,尝试将--verbose --stacktrace添加到compileshell命令中-您可能会丢失警告或错误消息:

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

请注意,grails-app/utils的名称具有误导性。不是用于实用程序类,而是用于编解码器。将所有不是grails-app构件( Controller ,服务,编解码器等)的Groovy和Java代码放入src/groovysrc/java中。

关于hibernate - grails自定义GORM方言阻止 'grails shell'起作用-类路径之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27669529/

相关文章:

java - 在 JUnit 中比较两个 Hibernate session 是否相同

rest - Grails Restful Controller无法保存在POST上

grails - 如何使用 Groovy 修剪列表中的所有元素?

hibernate - 将dynamicUpdate设置为true的Grails Gorm beforeUpdate行为

unit-testing - 如何在grails 2.2.4单元测试中用withCriteria模拟?

java - 为什么 Jersey 要求我在项目中包含 Bean 验证依赖项?

mysql - 如何在单独的文件中使用 DB 设置连接多个数据库(hsqldb、mysql)

java - 为什么 SpEL 支持在 Spring Data JPA @Query 中不起作用?

grails - [method] 操作接受类型为 [org...JSONObject] 的参数,该参数未使用 @Validateable 标记。

hibernate - Grails的hasOne和hasMany具有相同的域和级联操作