我有一个名为Regra
的域类,它具有以下代码:
Map<String, Permissao> permissoes = [:]
static hasMany = [permissoes: Permissao]
当我使用默认的内存grails数据库(
jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
)时,此方法工作正常。但是当我开始使用SQL Server时,控制台日志中开始出现一些错误。
当我第一次尝试将条目添加到
Regra
域类时,得到以下堆栈跟踪:java.util.LinkedHashMap cannot be cast to java.lang.Number. Stacktrace follows:
Message: java.util.LinkedHashMap cannot be cast to java.lang.Number
Line | Method
->> 38 | doToString in org.compass.core.converter.basic.AbstractNumberConverter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 189 | toString in org.compass.core.converter.basic.AbstractBasicConverter
| 54 | marshall . . . . . . . . in ''
| 435 | convertId in org.compass.core.converter.mapping.osem.ClassMappingConverter
| 410 | marshallIds . . . . . . in ''
| 87 | marshallIds in org.compass.core.marshall.DefaultMarshallingStrategy
| 76 | doMarshall . . . . . . . in org.compass.core.converter.mapping.osem.ReferenceMappingConverter
| 48 | marshall in org.compass.core.converter.mapping.osem.AbstractRefAliasMappingConverter
| 213 | doMarshall . . . . . . . in org.compass.core.converter.mapping.osem.ClassMappingConverter
| 97 | marshall in ''
| 154 | marshall . . . . . . . . in org.compass.core.marshall.DefaultMarshallingStrategy
| 408 | create in org.compass.core.impl.DefaultCompassSession
| 397 | create . . . . . . . . . in ''
| 305 | create in org.compass.core.impl.ExistingCompassSession
| 218 | doInsert . . . . . . . . in org.compass.gps.device.hibernate.lifecycle.HibernateEventListener
| 101 | doInCompassWithoutResult in org.compass.gps.device.hibernate.lifecycle.HibernateEventListener$1
| 29 | doInCompass . . . . . . in org.compass.core.CompassCallbackWithoutResult
| 133 | execute in org.compass.core.CompassTemplate
| 151 | executeForMirror . . . . in org.compass.gps.impl.SingleCompassGps
| 99 | onPostInsert in org.compass.gps.device.hibernate.lifecycle.HibernateEventListener
| 50 | $tt__save . . . . . . . in security.RegraController
| 200 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 449 | executeChain in org.apache.shiro.web.servlet.AbstractShiroFilter
| 365 | call . . . . . . . . . . in org.apache.shiro.web.servlet.AbstractShiroFilter$1
| 90 | doCall in org.apache.shiro.subject.support.SubjectCallable
| 83 | call . . . . . . . . . . in ''
| 383 | execute in org.apache.shiro.subject.support.DelegatingSubject
| 362 | doFilterInternal . . . . in org.apache.shiro.web.servlet.AbstractShiroFilter
| 125 | doFilter in org.apache.shiro.web.servlet.OncePerRequestFilter
| 1145 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . . . . . . . . in java.lang.Thread
如果我对
Regra
域类进行了任何更改(甚至添加空白行之类的东西),然后等到Grails重新加载该类,那么一切都会正常进行。这是我在表Regra已经有一些数据后重新启动服务器时得到的stacktrace:
2014-04-04 08:42:09,281 [Compass Gps Index [pool-8-thread-14]] ERROR indexer.ScrollableHibernateIndexEntitiesIndexer - {hibernate}: Failed to index the database
Message: org.hibernate.collection.PersistentMap cannot be cast to java.lang.Number
Line | Method
->> 38 | doToString in org.compass.core.converter.basic.AbstractNumberConverter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 189 | toString in org.compass.core.converter.basic.AbstractBasicConverter
| 54 | marshall . . . . . . . . in ''
| 435 | convertId in org.compass.core.converter.mapping.osem.ClassMappingConverter
| 410 | marshallIds . . . . . . in ''
| 87 | marshallIds in org.compass.core.marshall.DefaultMarshallingStrategy
| 76 | doMarshall . . . . . . . in org.compass.core.converter.mapping.osem.ReferenceMappingConverter
| 48 | marshall in org.compass.core.converter.mapping.osem.AbstractRefAliasMappingConverter
| 213 | doMarshall . . . . . . . in org.compass.core.converter.mapping.osem.ClassMappingConverter
| 97 | marshall in ''
| 154 | marshall . . . . . . . . in org.compass.core.marshall.DefaultMarshallingStrategy
| 408 | create in org.compass.core.impl.DefaultCompassSession
| 397 | create . . . . . . . . . in ''
| 305 | create in org.compass.core.impl.ExistingCompassSession
| 212 | flush . . . . . . . . . in org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer$RowBuffer
| 206 | close in ''
| 151 | performIndex . . . . . . in org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer
| 104 | doInCompassWithoutResult in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1$1
| 29 | doInCompass . . . . . . in org.compass.core.CompassCallbackWithoutResult
| 133 | execute in org.compass.core.CompassTemplate
| 147 | executeForIndex . . . . in org.compass.gps.impl.SingleCompassGps
| 102 | call in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1
| 262 | run . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Error |
2014-04-04 08:42:09,615 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Failed to index, execution exception; nested exception is java.util.concurrent.ExecutionException: org.compass.gps.device.hibernate.HibernateGpsDeviceException: {hibernate}: Failed to index the database; nested exception is java.lang.ClassCastException: org.hibernate.collection.PersistentMap cannot be cast to java.lang.Number
Message: Failed to index, execution exception; nested exception is java.util.concurrent.ExecutionException: org.compass.gps.device.hibernate.HibernateGpsDeviceException: {hibernate}: Failed to index the database; nested exception is java.lang.ClassCastException: org.hibernate.collection.PersistentMap cannot be cast to java.lang.Number
Line | Method
->> 126 | performIndex in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 119 | index in org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
| 42 | buildIndexIfNeeded in org.compass.gps.impl.DefaultReplaceIndexCallback
| 281 | firstStep in org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager$ReplaceIndexOperationCallback
| 218 | doOperate . . . . in org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager
| 266 | doReplaceIndex in ''
| 261 | replaceIndex . . . in ''
| 118 | doIndex in org.compass.gps.impl.SingleCompassGps
| 154 | index . . . . . . in org.compass.gps.impl.AbstractCompassGps
| 128 | index in ''
| 49 | index . . . . . . in grails.plugin.searchable.internal.compass.CompassGpsUtils
| 157 | doCall in SearchableGrailsPlugin$_closure3
| 262 | run . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by ExecutionException: org.compass.gps.device.hibernate.HibernateGpsDeviceException: {hibernate}: Failed to index the database; nested exception is java.lang.ClassCastException: org.hibernate.collection.PersistentMap cannot be cast to java.lang.Number
->> 122 | report in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 188 | get in ''
| 122 | performIndex . . . in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor
| 119 | index in org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
| 42 | buildIndexIfNeeded in org.compass.gps.impl.DefaultReplaceIndexCallback
| 281 | firstStep in org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager$ReplaceIndexOperationCallback
| 218 | doOperate . . . . in org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager
| 266 | doReplaceIndex in ''
| 261 | replaceIndex . . . in ''
| 118 | doIndex in org.compass.gps.impl.SingleCompassGps
| 154 | index . . . . . . in org.compass.gps.impl.AbstractCompassGps
| 128 | index in ''
| 49 | index . . . . . . in grails.plugin.searchable.internal.compass.CompassGpsUtils
| 157 | doCall in SearchableGrailsPlugin$_closure3
| 262 | run . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by HibernateGpsDeviceException: {hibernate}: Failed to index the database; nested exception is java.lang.ClassCastException: org.hibernate.collection.PersistentMap cannot be cast to java.lang.Number
->> 172 | performIndex in org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 104 | doInCompassWithoutResult in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1$1
| 29 | doInCompass . . . in org.compass.core.CompassCallbackWithoutResult
| 133 | execute in org.compass.core.CompassTemplate
| 147 | executeForIndex . in org.compass.gps.impl.SingleCompassGps
| 102 | call in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1
| 262 | run . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by ClassCastException: org.hibernate.collection.PersistentMap cannot be cast to java.lang.Number
->> 38 | doToString in org.compass.core.converter.basic.AbstractNumberConverter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 189 | toString in org.compass.core.converter.basic.AbstractBasicConverter
| 54 | marshall . . . . . in ''
| 435 | convertId in org.compass.core.converter.mapping.osem.ClassMappingConverter
| 410 | marshallIds . . . in ''
| 87 | marshallIds in org.compass.core.marshall.DefaultMarshallingStrategy
| 76 | doMarshall . . . . in org.compass.core.converter.mapping.osem.ReferenceMappingConverter
| 48 | marshall in org.compass.core.converter.mapping.osem.AbstractRefAliasMappingConverter
| 213 | doMarshall . . . . in org.compass.core.converter.mapping.osem.ClassMappingConverter
| 97 | marshall in ''
| 154 | marshall . . . . . in org.compass.core.marshall.DefaultMarshallingStrategy
| 408 | create in org.compass.core.impl.DefaultCompassSession
| 397 | create . . . . . . in ''
| 305 | create in org.compass.core.impl.ExistingCompassSession
| 212 | flush . . . . . . in org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer$RowBuffer
| 206 | close in ''
| 151 | performIndex . . . in org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer
| 104 | doInCompassWithoutResult in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1$1
| 29 | doInCompass . . . in org.compass.core.CompassCallbackWithoutResult
| 133 | execute in org.compass.core.CompassTemplate
| 147 | executeForIndex . in org.compass.gps.impl.SingleCompassGps
| 102 | call in org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1
| 262 | run . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
最佳答案
从栈跟踪中可以看出,异常是在索引操作中引发的。这可能是域类和搜索索引之间的映射问题。