Possible issue for JPQL IS EMPTY expression

#1

Possible issue for JPQL IS EMPTY comparison expression:

SELECT e FROM MyEntity e WHERE e.collection-valued IS EMPTY

throws javax.persistence.PersistenceException:
Invalid operand type  for operator IS EMPTY (error 756)

Thanks.

Note: It doesn' t work with SIZE():

SELECT e FROM MyEntity e WHERE SIZE(e.collection-valued)=0

 

#2

Please follow the posting instructions and provide test cases for your questions / issues.

This time you may base your test on the following example, in which IS EMPTY works well:

import java.util.*;

import javax.persistence.*;
import javax.persistence.Query;


public class T759 {

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

        em.getTransaction().begin();
        em.persist(new MyEntity());
        em.getTransaction().commit();
       
        Query query = em.createQuery(
            "SELECT e FROM MyEntity e WHERE e.list IS EMPTY");
        System.out.println(query.getResultList().size());

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

    @Entity
    public static class MyEntity {
        List<MyEntity> list = new ArrayList<MyEntity>();
    }
}
ObjectDB Support
#3

It is little bit more complicated for a collection-valued relationship bidirectional and not a field:

@Entity
class MyEntity {
    @OneToMany(mappedBy="myentity")
    ArrayList<OtherEntity> others = new ArrayList<OtherEntity>();
    void addOtherEntity(OtherEntity other) {
        others.add(other);
    }  
}

@Entity
class OtherEntity { 
    @ManyToOne
    MyEntity myentity;        
}

Thanks.

#4

You are right. Unfortunately collection operators are currently not supported for mapped by (inverse) collections.

Please see more details and a possible workaround in this new issue.

Hopefully this will be solved soon.

ObjectDB Support

Reply