I am using the hector HOM library to access my cassandra datastore. This library is written in java and uses some reflexion when working with Collections.
I have a java Model that contains a List of Strings that I want to retrieve. Unfortunately I get the following exception:
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]
I have tried explicitly creating a java.util.list object but it still causes the same problems. Here is my code to create and persist my model:
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)
The model persists fine and I can see it in cassandra as:
(column=things, value=scala.collection.JavaConversions$SeqWrapper:0, timestamp=1333555422145002)
The problem is when retrieving the object back it appears Hector doens't know how to handle the scala.collection type.
Is there anyway to get around this?
Thanks.
edit:
Sorry... misleading toString impl of scala.collection.JavaConversions$SeqWrapper it returns the same...
You could however create a java.util.List from your List yourself as a workaround.
original:
instead of collection.JavaConversion you could use collections.JavaConverters.
scala> import collection.JavaConverters._
import collection.JavaConverters._
scala> List(1,2,3).asJava
res1: java.util.List[Int] = [1, 2, 3]