Home » Support » Forum » Entity has be persistended,but query not fetched?

Entity has be persistended,but query not fetched?

#1

I create a new entity T newT and persistend it,then I create a query "select t from T t" to fetch all T entities.But  then the newT is not contain in the query result. Why?

code order:

query.setFlushMode(FlushModeType.AUTO);

query.getResultList();

 

#2

The following example demonstrates how it works:

public final class FlushQueryTest
{
    public static void main(String[] args)
    {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("$objectdb/flush.odb");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
       
        User user = new User();
        em.persist(user);

        Query query = em.createQuery("SELECT u FROM User u");
        query.setFlushMode(FlushModeType.AUTO);
        System.out.println("count: " + query.getResultList().size());

        em.getTransaction().rollback();
        em.close();
        emf.close();
    }
   
    @Entity
    static final class User {}
}

Maybe you are using a different EntityManager for the query?

Updates can only be visible before commit in the EntityManager that was used to apply the updates.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thanks!

I are using a different EntityManager for the query.


Post Reply

To post a reply and/or subscribe to update notifications - please login