#838834 : fixed validation for SQL queries

This commit is contained in:
Timo Westkämper 2011-09-01 17:57:14 +03:00
parent 593743d1ff
commit f7ca698c0f
5 changed files with 42 additions and 2 deletions

View File

@ -1,6 +1,6 @@
----------------------------------------------------------------
Wed Aug 10 16:05:39 EEST 2011:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.8.1.2 - (1095077): instance a816c00e-0131-b3cc-5aa8-000002fc9e58
Thu Sep 01 17:55:58 EEST 2011:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.8.1.2 - (1095077): instance a816c00e-0132-257d-41db-0000030c13f0
on database directory /home/tiwe/work/querydsl/querydsl-jpa/target/derbydb with class loader sun.misc.Launcher$AppClassLoader@1a16869
Loaded from file:/home/tiwe/.m2/repository/org/apache/derby/derby/10.8.1.2/derby-10.8.1.2.jar
java.vendor=Sun Microsystems Inc.

View File

@ -83,6 +83,7 @@ public abstract class AbstractHibernateSQLQuery<Q extends AbstractHibernateSQLQu
}
public Query createQuery(Expression<?>... args){
queryMixin.getMetadata().setValidate(false);
queryMixin.addToProjection(args);
return createQuery(toQueryString());
}

View File

@ -67,6 +67,7 @@ public abstract class AbstractJPASQLQuery<Q extends AbstractJPASQLQuery<Q>> exte
}
public Query createQuery(Expression<?>... args){
queryMixin.getMetadata().setValidate(false);
queryMixin.addToProjection(args);
return createQuery(toQueryString());
}

View File

@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.junit.Before;
import org.junit.Test;
@ -136,7 +137,25 @@ public abstract class AbstractSQLTest {
.list(catEntity);
assertTrue(cats.isEmpty());
}
@Test
public void EntityQueries_CreateQuery() {
SAnimal cat = new SAnimal("cat");
QCat catEntity = QCat.cat;
Query query = query().from(cat).createQuery(catEntity);
assertEquals(6, query.list().size());
}
@Test
public void EntityQueries_CreateQuery2() {
SAnimal cat = new SAnimal("CAT");
QCat catEntity = QCat.cat;
Query query = query().from(cat).createQuery(catEntity);
assertEquals(6, query.list().size());
}
@Test
public void EntityProjections(){
SAnimal cat = new SAnimal("cat");

View File

@ -14,6 +14,7 @@ import java.util.List;
import java.util.UUID;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.junit.Before;
import org.junit.Ignore;
@ -157,6 +158,24 @@ public class JPADerbySQLTest {
.list(catEntity);
assertTrue(cats.isEmpty());
}
@Test
public void EntityQueries_CreateQuery() {
SAnimal cat = new SAnimal("cat");
QCat catEntity = QCat.cat;
Query query = query().from(cat).createQuery(catEntity);
assertEquals(6, query.getResultList().size());
}
@Test
public void EntityQueries_CreateQuery2() {
SAnimal cat = new SAnimal("CAT");
QCat catEntity = QCat.cat;
Query query = query().from(cat).createQuery(catEntity);
assertEquals(6, query.getResultList().size());
}
@Test
@Ignore