我正在使用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 clean
和grails compile
,是否有帮助?另外,尝试将--verbose --stacktrace
添加到compile
和shell
命令中-您可能会丢失警告或错误消息:
$ grails clean
$ grails compile --verbose --stacktrace
$ grails shell --verbose --stacktrace
请注意,
grails-app/utils
的名称具有误导性。不是用于实用程序类,而是用于编解码器。将所有不是grails-app构件( Controller ,服务,编解码器等)的Groovy和Java代码放入src/groovy
和src/java
中。
关于hibernate - grails自定义GORM方言阻止 'grails shell'起作用-类路径之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27669529/