当我升级到grails 2.0项目(新安装了可搜索插件)时,我会得到一个Hibernate类强制转换异常。其他人有这个问题吗?
http://grails.org/使用Searchable插件,可以与Grails 2.0.3配合使用。你遇到了什么问题?
Searchable是基于Compass的,它被重写为ElasticSearch。
ElasticSearch插件适用于Grails 2.0。
欲了解更多信息,请参阅指南针的未来;ElasticSearch。
将我的应用程序从Grails 1.3.7迁移到2.1.1也遇到了类似的问题。我通过将Searchable插件从0.5.5更新到0.6.4解决了这个问题。
堆叠竞赛是这样的:
| Error 2012-10-05 19:02:18,691 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
Message: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
Line
| Method
->> 95 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityLifecycleInjector
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 46 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityCollectionLifecycleInjector
| 149 | doStart . . . . in org.compass.gps.device.hibernate.HibernateGpsDevice
| 125 | start in org.compass.gps.device.AbstractGpsDevice
| 73 | start . . . . . in org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
| 166 | start in org.compass.gps.impl.AbstractCompassGps
| 144 | doCall . . . . in SearchableGrailsPlugin$_closure3
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . . . . . in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . in ''
^ 680 | run in java.lang.Thread
| Error 2012-10-05 19:02:18,715 [localhost-startStop-1] ERROR [localhost].[/myApp] - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
Message: Error executing bootstraps; nested exception is java.lang.ClassCastException: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by ClassCastException: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
->> 95 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityLifecycleInjector
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 46 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityCollectionLifecycleInjector
| 149 | doStart in org.compass.gps.device.hibernate.HibernateGpsDevice
| 125 | start in org.compass.gps.device.AbstractGpsDevice
| 73 | start . in org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
| 166 | start in org.compass.gps.impl.AbstractCompassGps
| 144 | doCall . in SearchableGrailsPlugin$_closure3
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . in ''
^ 680 | run in java.lang.Thread
是的,我也曾在grails 1.3.7、2.0.3上使用过可搜索功能,现在在2.1.1 上使用
我所要做的就是将我的可搜索插件升级到最新的插件。虽然我不得不对代码进行一些调整,但插件文档中提到了每一件事
文件链接
注意控制器中的导入。正如我所猜测的,类路径已经改变了。这是我唯一的改变。
之所以会发生这种情况,是因为当您升级到使用Hibernate 4.X的Grails版本时。之所以会出现这种情况,是因为Hiberate3.x和4.x之间发生了多次包和类名更改,所以使用Hibernate 3.x的代码将无法使用4.x,除非在极少数情况下。除了名称更改之外,工作方式也发生了巨大的内部变化,因此编译的代码不一定会运行。应用程序选项#1是降级到Hibernate 3.x。它的配置设置包括在内并被注释掉(BuildConfig.groovy,DataSource.groovy),所以这是一个非常快速的选项。如果您依赖4.x中添加的功能,显然这不是一个选项,这只会将真正的问题推迟到您必须升级Hibernate。