Query by array element



I have a class as follows:

public class MyEntity {
    boolean properties[]= new boolean[1024]; 

I would like to query objects with feature '42':

select me from MyEntity me where me.properties[42]=true

Is it possible?

Thank you!


This query is not supported since you cannot access arrays in queries.

You can implement a method in MyEntity that wraps the array access operation and then use that method in the query. It is supported by ObjectDB but not JPA portable:

import javax.persistence.*;

public class T1654 {

    public static void main(String[] args) {

        EntityManagerFactory emf =
        EntityManager em = emf.createEntityManager();

        em.persist(new MyEntity());
        Query query = em.createQuery(
            "SELECT me FROM MyEntity me WHERE me.isProperty(42)");       
    public static class MyEntity {
        boolean properties[] = new boolean[1024];
        boolean isProperty(int index) {
            return properties[index];
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

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