ObjectDB ObjectDB

Get multiple entities by Id

#1

I'm trying to fetch a list of entities, by their Id. I Use this query:

SELECT c FROM User c WHERE c.id IN :ids

This querey works as long as I don't set the property "id" as @Id.

If i set @Id to any other member, this query works, if I set id as @Id, it stops working and gives zero results. Is this a known limitation or a bug? Do you have any idea how to solve this problem?

edit
delete
#2

Just found out thath it seems to work correctly with 2.3.7 and fails with 2.4.3_03

edit
delete
#3

Could you please post a sample test case that demonstrates the problem?

Something simple in this format will be very helpful.

ObjectDB Support
edit
delete
#4

I could reproduce the problem with this test case:

import java.util.*;
import javax.persistence.*;


public final class demo {

    public static void main(String[] args)  {
        EntityManagerFactory emf =
                Persistence.createEntityManagerFactory(
                        "objectdb:$objectdb/db/test.tmp;drop");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();
        MyEntity e1 = new MyEntity("test1");
        em.persist(e1);
        MyEntity e2 = new MyEntity("test2");
        em.persist(e2);
        MyEntity e3 = new MyEntity("test3");
        em.persist(e3);
        em.getTransaction().commit();

        ArrayList<String> idsToRequest = new ArrayList<String>();
        idsToRequest.add("test2");
        idsToRequest.add("test3");

        Query query1 = em.createQuery("SELECT e FROM MyEntity e WHERE e.id IN :id");
        query1.setParameter("id",idsToRequest);
        List resultList1 = query1.getResultList();
        System.out.println(resultList1);

        Query query2 = em.createQuery("SELECT e FROM MyEntity e WHERE e.name IN :id");
        query2.setParameter("id",idsToRequest);
        List resultList2 = query2.getResultList();
        System.out.println(resultList2);

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

    @Entity
    public static class MyEntity {

        private String name;

        @Id
        private String id;

        MyEntity(String name) {
            this.name = name;
            this.id=name;
        }
        @Override
        public String toString() {
            return name;
        }
    }
}
edit
delete
#5

Thank you for the test case.

Actually the test passes also with ObjectDB 2.4.3, since this regression was added in build 2.4.3_01 (as a result of fixing another problem).

Please try build 2.4.3_04 that should fix the new problem.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.