我正在尝试进行查询,但没有运气。我正在 AppEngine 上开发,使用 JPA 进行数据访问。当我将查询字符串设置为:
"SELECT m FROM ModelLocationJPA m WHERE m.latitude BETWEEN :lowerLatitude AND :higherLatitude"
它有效,而且:
"SELECT m FROM ModelLocationJPA m WHERE m.longitude BETWEEN :lowerLongitude AND :higherLongitude"
作品。所以,我想那是因为我用多个“AND”弄乱了一些东西,但我不知道是什么。
我正在尝试进行以下工作,但出现错误: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();
}
如果有人可以告诉我出了什么问题,那就太好了。谢谢你。