我正在使用 hector HOM 库来访问我的 cassandra 数据存储。这个库是用 java 编写的,在使用 Collections 时使用了一些反射。
我有一个 java 模型,其中包含我要检索的字符串列表。不幸的是,我得到以下异常:
Execution exception [[HectorObjectMapperException: exception while instantiating Collection type, scala.collection.JavaConversions$SeqWrapper]]
Caused by: me.prettyprint.hom.cache.HectorObjectMapperException: exception while instantiating Collection type, scala.collection.JavaConversions$SeqWrapper
at me.prettyprint.hom.CollectionMapperHelper.instantiateCollection(CollectionMapperHelper.java:87) ~[hector-object-mapper-3.0-02.jar:na]
at me.prettyprint.hom.HectorObjectMapper.createObject(HectorObjectMapper.java:297) ~[hector-object-mapper-3.0-02.jar:na]
at me.prettyprint.hom.HectorObjectMapper.getObject(HectorObjectMapper.java:105) ~[hector-object-mapper-3.0-02.jar:na]
at me.prettyprint.hom.EntityManagerImpl.find(EntityManagerImpl.java:132) ~[hector-object-mapper-3.0-02.jar:na]
Caused by: java.lang.InstantiationException: scala.collection.JavaConversions$SeqWrapper
at java.lang.Class.newInstance0(Class.java:340) ~[na:1.6.0_29]
at java.lang.Class.newInstance(Class.java:308) ~[na:1.6.0_29]
at me.prettyprint.hom.CollectionMapperHelper.instantiateCollection(CollectionMapperHelper.java:75) ~[hector-object-mapper-3.0-02.jar:na]
at me.prettyprint.hom.HectorObjectMapper.createObject(HectorObjectMapper.java:297) ~[hector-object-mapper-3.0-02.jar:na]
我已经尝试显式创建一个 java.util.list 对象,但它仍然会导致同样的问题。这是我创建和持久化模型的代码:
val geoModel = new GeoModel(geoRK)
val thingList: java.util.List[java.lang.String] = things match {
case Some(t) => t.map(s => s.toString())
case None => new java.util.ArrayList()
}
geoModel.setThings(thingList)
geoDAO.upsertModel(geoModel)
该模型仍然很好,我可以在 cassandra 中看到它:
(column=things, value=scala.collection.JavaConversions$SeqWrapper:0, timestamp=1333555422145002)
问题是当检索对象时,赫克托似乎不知道如何处理 scala.collection 类型。
有没有办法解决这个问题?
谢谢。