impetus-opensource/Kundera-Examples — Issue #5: get all query doesn't work
Author: fcaballero
Created: 2011-12-22 15:27:05+00:00
State: open

hi, well i hope that you can understand me, i'm trying to execute a little test about how insert and get data with cassandra following your examples, but making debug, when i try to get all the data stored in DB i saw that i always get the last data that i have inserted making a simple query (select u from User u).

for example: i insert this

em.persist(user1)
em.persist(user2)

and i get a list with user1 and user2

and then i insert this

em.persist(user3)
em.persist(user4)

and i expect a list with user1, user2, user3 and user4 but i get a list with user3 and user4

i don't what is going on.. :S

well i need a litlle help with this i hope..can find it :P

this is the test code, thanks:

public void testApp()
{
User user = new User();
user.setUserId("0001");
user.setFirstName("Juanito");
user.setLastName("Gomez");
user.setCity("Madrid");

User user2 = new User();
user.setUserId("0002");
user.setFirstName("Pepito");
user.setLastName("Gomez");
user.setCity("Madrid");

EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu");
EntityManager em = emf.createEntityManager();

em.persist(user);
em.persist(user2);
em.clear();
em.close();

user = new User();
user.setUserId("0003");
user.setFirstName("Felipe");
user.setLastName("Gomez");
user.setCity("Madrid");

user2 = new User();
user.setUserId("0004");
user.setFirstName("Sara");
user.setLastName("Gomez");
user.setCity("Madrid");

em = emf.createEntityManager();

em.persist(user);
em.persist(user2);
em.clear();
em.close();

em = emf.createEntityManager();
em.clear();

Query q = em.createQuery("select u from User u");
List requestInfos = (List)q.getResultList();

em.close();
emf.close();
}