Fork me on GitHub

Torpedo Query Build Status Maven Central Javadoc


HQL query faster and safer

Use your real classes to construct complex queries and unleash the power of your IDE to maintain and validate them.

Start now

Subscribe to our newsletter

Subscribe

Before

Map<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();

After

SampleObject from = from(SampleObject.class);
where(from.getNumber()).gt(4).and(from.getGroupName()).eq("supergroup");
List<SampleObject> result = select(from).list(manager);

Maven

	<dependency>
    		<groupId>org.torpedoquery</groupId>
    		<artifactId>org.torpedoquery</artifactId>
    		<version>1.7.0</version>
	</dependency>