Use your real classes to construct complex queries and unleash the power of your IDE to maintain and validate them.
Start nowMap<String,Object> params = new HashMap<String,Object>(); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("select myVar from SampleObject myVar "); queryBuilder.append("where myVar.number > :number and myVar.groupName = :name"); params.put("number",4); params.put("name","supergroup"); Query query = entityManager.createQuery(queryBuilder.toString()); for ( Map.Entry<String,Object>; param : params.entrySet()) { query.setParameter(param.getKey(),param.getValue()); } List<SampleObject> result = (List<SampleObject>)query.getResultList();
SampleObject from = from(SampleObject.class); where(from.getNumber()).gt(4).and(from.getGroupName()).eq("supergroup"); List<SampleObject> result = select(from).list(manager);
<dependency> <groupId>org.torpedoquery</groupId> <artifactId>org.torpedoquery</artifactId> <version>1.7.0</version> </dependency>