Grails shell没有看到域对象
发布时间:2020-12-15 18:18:47 所属栏目:安全 来源:网络整理
导读:我是一个grails新手(和一个时髦的新手),我正在通过一些grails教程.作为一个新用户,grails shell对我来说是一个非常有用的小工具,但我无法弄清楚如何让它看到我的类和对象.这是我正在尝试的: % grails create-app test% cd test% grails create-domain-class
我是一个grails新手(和一个时髦的新手),我正在通过一些grails教程.作为一个新用户,grails
shell对我来说是一个非常有用的小工具,但我无法弄清楚如何让它看到我的类和对象.这是我正在尝试的:
% grails create-app test % cd test % grails create-domain-class com.test.TestObj % grails shell groovy:000> new TestObj() ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,groovysh_evaluate: 2: unable to resolve class TestObj 我的印象是grails shell可以看到所有控制器,服务和域对象.怎么了?我需要在这里做点什么吗? 我尝试了另外一件事: groovy:000> foo = new com.test.TestObj(); ===> com.test.TestObj : null groovy:000> foo.save ERROR groovy.lang.MissingPropertyException: No such property: save for class: com.test.TestObj 我究竟做错了什么? 编辑:好的,我看到了关于使用全名并使用.save()而不是.save的答案.但是这个怎么样? groovy:000> new com.test.TestObj().save() ERROR org.hibernate.HibernateException: No Hibernate Session bound to thread,and configuration does not allow creation of non-transactional one here 这次我做错了什么? 解决方法
我是第二个Burt的建议,使用控制台而不是shell.关于例外:
groovy:000> new com.test.TestObj().save() ERROR org.hibernate.HibernateException: No Hibernate Session bound to thread,and configuration does not allow creation of non-transactional one here 您可以尝试使用事务显式运行此代码: import com.test.TestObj TestObj.withTransaction{ status -> TestObj().save() } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |