Getting entities with Astyanax EntityManager sets IDs all to same value

22 views
Skip to first unread message

Lorena Nicole

unread,
Nov 12, 2014, 2:43:23 PM11/12/14
to astyanax-cas...@googlegroups.com

When fetching entities from Cassandra with Astyanax's Entity Manager all of the column properties are properly set however all of the entities have an ID of the same value (the last entity fetched with get). I believe I've either improperly set the entity mapping on my object or else I am overlooking a command I need to run on the Entity Manager after I get an entity. Quick info, using Twitter4J's User implementation for CassandraTwitterUser.

Reading from Cassandra with Astyanax:

List<CassandraTwitterUser> cassList = new ArrayList<CassandraTwitterUser>(other_tw_user_ids.size());

ColumnFamily<Long, String> CF_USER_INFO = new ColumnFamily<Long, String>("testusers", LongSerializer.get(), StringSerializer.get());

final EntityManager<CassandraTwitterUser, Long> entityManager = new DefaultEntityManager.Builder<CassandraTwitterUser, Long>()
                                                                            .withEntityType(CassandraTwitterUser.class)
                                                                            .withKeyspace(keyspace)
                                                                            .withColumnFamily(CF_USER_INFO)                                     
                                                                            .build();

    for (Long tw_user_id: other_tw_user_ids) {
        System.out.println("ID to fetch: " + tw_user_id);
        CassandraTwitterUser cassU = entityManager.get(tw_user_id);
        System.out.println("Here is result of entity manager getting twitter user id: " + cassU.getId()); // ID is accurate
        cassList.add(cassU);
        }
    }

for (CassandraTwitterUser c : cassList) {
     System.out.println(c.getId()); // IDs now have value of the last user ID (row key) retrieved from Cassandra
}

CassandaTwitterUser class --

import twitter4j.RateLimitStatus;
import twitter4j.Status;
import twitter4j.URLEntity;
import twitter4j.User;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;


@Entity
public class CassandraTwitterUser implements User {

    @Id
    private static long id;

    @Column(name="name")
    private String name;

    // more columns 

    @Override
    public long getId() {
    return id;
    }

    // more methods for fetching column values
}
I'm new to Astyanax so I believe there is a step I am missing in the get lookup. Any help is greatly appreciated, thank you!

Reply all
Reply to author
Forward
0 new messages