HHH-9154 : HQL Parsing: unexpected token ':' (test case)

This commit is contained in:
Gail Badner 2014-05-13 14:36:18 -07:00
parent 80f2b1f564
commit b046b644b8
1 changed files with 49 additions and 0 deletions

View File

@ -262,6 +262,55 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@FailureExpected( jiraKey = "HHH-9154" )
public void testClassAsParameter() {
// just checking syntax here...
Session s = openSession();
s.beginTransaction();
///////////////////////////////////////////////////////////////
// where clause
// control
s.createQuery( "from Animal a where a.class = :class" ).setParameter( "class", Dog.class ).list();
///////////////////////////////////////////////////////////////
// select clause (at some point we should unify these)
// control
Query query = s.createQuery( "select a.class from Animal a where a.class = :class" ).setParameter( "class", Dog.class );
query.list(); // checks syntax
assertEquals( 1, query.getReturnTypes().length );
assertEquals( Integer.class, query.getReturnTypes()[0].getReturnedClass() ); // always integer for joined
// test
query = s.createQuery( "select type(a) from Animal a where type(a) = Dog" );
query.list(); // checks syntax
assertEquals( 1, query.getReturnTypes().length );
assertEquals( DiscriminatorType.class, query.getReturnTypes()[0].getClass() );
assertEquals( Class.class, query.getReturnTypes()[0].getReturnedClass() );
s.getTransaction().commit();
s.close();
}
@Test
@FailureExpected( jiraKey = "HHH-9154" )
public void testObjectAsParameter() {
Session s = openSession();
s.beginTransaction();
Type[] types = s.createQuery( "select h.name from Human h" ).getReturnTypes();
assertEquals( 1, types.length );
assertTrue( types[0] instanceof ComponentType );
s.createQuery( "from Human h where h.name = :Object" ).setParameter( "object", new Name() ).list();
s.createQuery( "from Human where name = :object" ).setParameter( "object", new Name() ).list();
s.createQuery( "from Human h where :object = h.name" ).setParameter( "object", new Name() ).list();
s.createQuery( "from Human h where :object <> h.name" ).setParameter( "object", new Name() ).list();
s.getTransaction().commit();
s.close();
}
@Test
public void testComponentJoins() {
Session s = openSession();