Berry
Berry

Reputation: 59

JPA query in appegine datastore not working

I am trying to make a query to work, but with no luck. I am developing on AppEngine, using JPA for data access. When I set the query string as:

"SELECT m FROM ModelLocationJPA m WHERE  m.latitude BETWEEN :lowerLatitude AND  :higherLatitude" 

it works, and also :

  "SELECT m FROM ModelLocationJPA m WHERE  m.longitude BETWEEN :lowerLongitude AND :higherLongitude"

works. So, I guess that is because I messed something with the multiple "AND"'s, but I can't figure out what.

I am trying to make the following work but I get the error: javax.persistence.PersistenceException: Illegal argument

EntityManager em = null;
    List<ModelLocationJPA> dbModelLocations = null;
    ArrayList<ModelLocation> modelLocations = new ArrayList<ModelLocation>();
    String aQuery = "SELECT m FROM ModelLocationJPA m WHERE  ( (m.latitude BETWEEN :lowerLatitude AND  :higherLatitude) AND ( m.longitude BETWEEN :lowerLongitude AND :higherLongitude ))";




    try {
         em = EMF.get().createEntityManager();
            Query query = em.createQuery(aQuery);
            query.setParameter("lowerLatitude",box.getMinLatitude());
            query.setParameter("higherLatitude",box.getMaxLatitude());
            query.setParameter("lowerLongitude",box.getMinLongitude());
            query.setParameter("higherLongitude",box.getMaxLongitude());

                 dbModelLocations = query.getResultList();

        } finally {
        em.close();
        }

If someone could please tell me what is wrong, it would be great. Thank you.

Upvotes: 1

Views: 999

Answers (1)

JB Nizet
JB Nizet

Reputation: 691755

The documentation says:

A query may only use inequality filters (<, <=, >=, >, !=) on one property across all of its filters.

Upvotes: 2

Related Questions