Hi trying to use Astyanax Entity persister.
https://github.com/Netflix/astyanax/wiki/Entity-persister

Playing around, so this is all in a JUnit test.

Everything seems to work, except when getting the object by id with
.get(id).  Looks like it fails when trying to create the object to map it
back to.

*
**        @Entity*
*        class User {*

*            @Id*
*            private String id = UUID.randomUUID().toString();*

*            @Column(name = "firstName")*
*            private String firstName = "Joe";*
*            @Column(name = "lastName")*
*            private String lastName = "Greenawalt";*

*            @Column(name="age")*
*            private int age;*

*            @Column(name = "phone_numbers")*
*            Map<String, String> phoneNumbers;*

*          public User(){*
*                phoneNumbers = new HashMap<String, String>();*

*                phoneNumbers.put("home", "338-229-4493");*
*                phoneNumbers.put("work", "757-229-4493");*

*            }*

*         .....removing setters and getters....
**



        }

        AstyanaxContext<Keyspace> context = new
AstyanaxContext.Builder().withAstyanaxConfiguration(new
AstyanaxConfigurationImpl()
                .setCqlVersion("3.0.0")
                .setTargetCassandraVersion("1.2")
        )
                //.forCluster("ClusterName")
                .forKeyspace(KEYSPACE_NAME)
                .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
                )
                .withConnectionPoolConfiguration(new
ConnectionPoolConfigurationImpl("MyConnectionPool")
                        .setPort(9160)
                        .setMaxConnsPerHost(1)
                        .setSeeds("127.0.0.1:9160")
                )
                .withConnectionPoolMonitor(new
CountingConnectionPoolMonitor())
                .buildKeyspace(ThriftFamilyFactory.getInstance());

        context.start();
        Keyspace keyspace = context.getClient();

        ColumnFamily<String, String> COLUMN_FAMILY = ColumnFamily
                .newColumnFamily(COLUMN_FAMILY_NAME, StringSerializer.get(),
                        StringSerializer.get());

        try{
            keyspace.dropColumnFamily(COLUMN_FAMILY);

            keyspace.dropKeyspace();
        } catch (Exception e){
            System.out.println("SWALLOWING NON EXISTENT DROP");
        }

        keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
                .put("strategy_options", ImmutableMap.<String,
Object>builder()
                        .put("replication_factor", "1")
                        .build())
                .put("strategy_class", "SimpleStrategy")
                .build()
        );

        assertNotNull(keyspace);




        keyspace.createColumnFamily(COLUMN_FAMILY, null);

        assertNotNull(COLUMN_FAMILY);

        EntityManager<User, String> entityManager =
                new DefaultEntityManager.Builder<User, String>()
                        .withEntityType(User.class)
                        .withKeyspace(keyspace)
                        .withColumnFamily(COLUMN_FAMILY)
                        .withTTL(3600)  // 1 hour
                        .build();

        User user = new User();

        String getUserId = user.getId();

        user.setFirstName("JOHNNY");

        entityManager.put(user);

        user.setAge(40);

        entityManager.put(user);


        User newUser = new User();

        newUser.setAge(2);

        entityManager.put(newUser);

        ColumnList<String> cl =
keyspace.prepareQuery(COLUMN_FAMILY).getKey(getUserId).execute().getResult();

        Assert.assertEquals(5, cl.size());
        Assert.assertEquals(user.getFirstName(),
cl.getColumnByName("firstName").getStringValue());

        User fetchedUser = entityManager.get(getUserId);

        assertNotNull(newUser);

        assertEquals(user, fetchedUser);


**I get the following error: *

*javax.persistence.PersistenceException: failed to get entity
f33605bb-d748-447f-946c-10929753ce4d*
*    at
com.netflix.astyanax.entitystore.DefaultEntityManager.get(DefaultEntityManager.java:227)
*
*    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
*    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
*
*    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
*
*    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
*
*    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
*
*    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
*
*    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
*
*    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
*
*    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)*
*    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
*
*    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
*
*    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)*
*    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)*
*    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)*
*    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)*
*    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)*
*    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)*
*    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)*
*    at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
*
*    at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
*
*    at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)*
*    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
*    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
*
*    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
*
*Caused by: javax.persistence.PersistenceException: failed to construct
entity*
*    at
com.netflix.astyanax.entitystore.EntityMapper.constructEntity(EntityMapper.java:162)
*
*    at
com.netflix.astyanax.entitystore.DefaultEntityManager.get(DefaultEntityManager.java:223)
*
*    ... 28 more*
*Caused by: java.lang.InstantiationException:
me.bagz.scratch.ConnectAndCreateTest$1User*
*    at java.lang.Class.newInstance0(Class.java:359)*
*    at java.lang.Class.newInstance(Class.java:327)*
*    at
com.netflix.astyanax.entitystore.EntityMapper.constructEntity(EntityMapper.java:149)
*
*    ... 29 more*

However, the object gets stored and I can get it with the low level API and
the tests prove it.  Pretty new to this library and cassandra, so I
certainly could be doing something wrong, but I was following the wiki, and
also reading the test here:
https://github.com/Netflix/astyanax/blob/master/astyanax-entity-mapper/src/test/java/com/netflix/astyanax/entitystore/DefaultEntityManagerTest.java
(LINE 234).

Any help appreciated.

Thanks,
Joe

Reply via email to