Problem with Java collections

51 views
Skip to first unread message

Kirill Chepyrev

unread,
Oct 6, 2011, 10:32:36 AM10/6/11
to hector-users
Hi guys!
Help me please understanding this example:
http://rantav.github.com/hector/build/html/content/HOM/hector-object-mapper.html#java-collections-mapping-a-pojo
Is it the error (String <=> Drawer)?
@Column(name = "drawerList")
private List<Drawer> drawerList = new ArrayList<Drawer>();

public List<String> getDrawerList() {
return drawerList;
}

public void setDrawerList(List<String> drawerList) {
this.drawerList = drawerList;
}
How can I deserialize my object? After

@Entity
@Table(name = "TestColumnFamily")
public class MyPojo {
@Id
private UUID id;

@Column(name = "lp1")
private long longProp1;

@Column(name = "list")
private List<String> myList = new ArrayList<String>();
...
}

MyPojo pojo1 = new MyPojo();
pojo1.setId(UUID.randomUUID());
pojo1.setLongProp1(123L);
pojo1.setColor(Colors.RED);
pojo1.getMyList().add("value1");
pojo1.getMyList().add("value2");
pojo1.getMyList().add("value3");
pojo1.getMyList().add("value4");

em.save(pojo1); // OK

MyPojo pojo2 = em.load(MyPojo.class, pojo1.getId()); //Exception here
I recive

Exception in thread "main" java.lang.RuntimeException: unsupported
property type, java.util.List
at
me.prettyprint.hom.HectorObjectMapper.determineSerializer(HectorObjectMapper.java:
528)
at
me.prettyprint.hom.converters.DefaultConverter.convertCassTypeToObjType(DefaultConverter.java:
18)
at
me.prettyprint.hom.HectorObjectMapper.setPropertyUsingColumn(HectorObjectMapper.java:
497)
at
me.prettyprint.hom.HectorObjectMapper.createObject(HectorObjectMapper.java:
214)
at
me.prettyprint.hom.HectorObjectMapper.getObject(HectorObjectMapper.java:
107)
at me.prettyprint.hom.EntityManagerImpl.load(EntityManagerImpl.java:
127)
at com.vi.MainProg.main(MainProg.java:33)

Nate McCall

unread,
Oct 6, 2011, 10:35:53 AM10/6/11
to hector...@googlegroups.com
Collection types cannot be mapped to columns. They need to be mapped
the appropriate one to many or similar relationships.

B. Todd Burruss

unread,
Oct 6, 2011, 2:58:31 PM10/6/11
to hector...@googlegroups.com
nate, actually I added this recently
(http://rantav.github.com/hector/build/html/content/HOM/hector-object-mapper.html#java-collections-mapping-a-pojo)

kirill, this new functionality is only available from the tip of the
0.8 or master branch - there hasn't been a build on HOM for release
yet. what version are you using?

Kirill Chepyrev

unread,
Oct 7, 2011, 4:07:19 AM10/7/11
to hector-users
Now I'm using 1.0-06. Should a use 2.0-01-SNAPSHOT from here
https://github.com/rantav/hector/tree/master/object-mapper?

On Oct 6, 10:58 pm, "B. Todd Burruss" <bto...@gmail.com> wrote:
> nate, actually I added this recently
> (http://rantav.github.com/hector/build/html/content/HOM/hector-object-...)
>
> kirill, this new functionality is only available from the tip of the
> 0.8 or master branch - there hasn't been a build on HOM for release
> yet.  what version are you using?
>
>
>
>
>
>
>
> On Thu, Oct 6, 2011 at 7:35 AM, Nate McCall <n...@datastax.com> wrote:
> > Collection types cannot be mapped to columns. They need to be mapped
> > the appropriate one to many or similar relationships.
>
> > On Thu, Oct 6, 2011 at 9:32 AM, Kirill Chepyrev <chepy...@gmail.com> wrote:
> >> Hi guys!
> >> Help me please understanding this example:
> >>http://rantav.github.com/hector/build/html/content/HOM/hector-object-...

B. Todd Burruss

unread,
Oct 9, 2011, 12:01:30 PM10/9/11
to hector...@googlegroups.com
you need either 1.1-03 (on the 0.8.0 branch) or 2.0-01 (on the master
branch). neither is a part of an official release yet, so you will
need to build it yourself for now.

Chris Chiappone

unread,
Oct 27, 2011, 7:26:18 PM10/27/11
to hector...@googlegroups.com
Am trying to get list to work also with HOM.  Here is my entity class

@Entity

@Table(name = "configs")

public class ConfigModel extends JsonModel {

public static String IDX_CONFIGNAME = "configname";

@Id

private String configname;

@Column(name = "subnamespaces")

private List<String> subnamespaces = new ArrayList<String>();

private Map<String,String> anonymousProps = new HashMap<String,String>();

@AnonymousPropertyAddHandler

public void addAnonymousProp(String name, String value){

anonymousProps.put(name, value);

}

@AnonymousPropertyCollectionGetter

public Collection<Entry<String, String>> getAnonymousProps() {

return anonymousProps.entrySet();

}

public String getAnonymousProp(String name) {

return anonymousProps.get(name);

}


public String getConfigname() {

return configname;

}


public void setConfigname(String configname) {

this.configname = configname;

}


public List<String> getSubnamespaces() {

return subnamespaces;

}

public void setSubnamespaces(List<String> subnamespaces) {

this.subnamespaces = subnamespaces;

}

}


Saving seems to work ok, but as with the previous user I get the following exception when i try to load:

java.lang.RuntimeException: unsupported property type, java.util.List

at me.prettyprint.hom.HectorObjectMapper.determineSerializer(HectorObjectMapper.java:605)

at me.prettyprint.hom.converters.DefaultConverter.convertCassTypeToObjType(DefaultConverter.java:18)

at me.prettyprint.hom.HectorObjectMapper.setPropertyUsingColumn(HectorObjectMapper.java:574)

at me.prettyprint.hom.HectorObjectMapper.createObject(HectorObjectMapper.java:250)

at me.prettyprint.hom.HectorObjectMapper.getObject(HectorObjectMapper.java:112)

at me.prettyprint.hom.EntityManagerImpl.load(EntityManagerImpl.java:125)

at com.twolemetry.dao.ConfigsDAO.getConfigModel(ConfigsDAO.java:45)

at com.twolemetry.dao.tests.DAOTests.saveAndGetConfigs(DAOTests.java:147)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)

at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)

at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)

at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)

at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)

at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)

at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)

at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)

at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)

at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)

at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)

at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


I am using hector-object-mapper-2.0-01.jar

Thanks.

B. Todd Burruss

unread,
Oct 27, 2011, 7:48:30 PM10/27/11
to hector...@googlegroups.com
make sure that @Column is from HOM, not javax.persistence

Chris Chiappone

unread,
Oct 28, 2011, 9:57:58 AM10/28/11
to hector...@googlegroups.com
Thanks that did it.

Sanja Vasic

unread,
Nov 4, 2013, 6:48:02 AM11/4/13
to hector...@googlegroups.com
How can i find documentation for HOM version 3.x. Stil on official page(Hector wiki - http://hector-client.github.io/hector/build/html/content/HOM/hector-object-mapper.html#if-i-annotate-a-base-class-with-entity-will-a-derived-class-be-persisted )  there are annotation that in newest version i didnt found. Where are @AnonymousPropertyAddHandler, @AnonymousPropertyCollectionGetter?  
Reply all
Reply to author
Forward
0 new messages