我正在使用hector HOM庫來訪問我的cassandra數據存儲。這個庫是用java編寫的,並且在使用Collections時使用了一些反射。將集合類型從scala轉換爲java的問題
我有一個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)
模型仍然存在很好,我可以看到它在卡桑德拉爲:
(column=things, value=scala.collection.JavaConversions$SeqWrapper:0, timestamp=1333555422145002)
問題檢索是當對象返回它的出現赫克託多恩斯不知道如何處理scala.collection類型。
有沒有辦法解決這個問題?
謝謝。
您應該使用'foreach'代替如果你不使用'map'的結果的話'map'。 – drexin 2012-04-05 21:15:42