Search in sources :

Example 26 with QueryException

use of org.hibernate.QueryException in project hibernate-orm by hibernate.

the class BulkManipulationTest method testUpdateNonExistentEntity.

@Test
public void testUpdateNonExistentEntity() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    try {
        s.createQuery("update NonExistentEntity e set e.someProp = ?").executeUpdate();
        fail("no exception thrown");
    } catch (IllegalArgumentException e) {
        assertTyping(QueryException.class, e.getCause());
    } catch (QueryException e) {
    }
    t.commit();
    s.close();
}
Also used : QueryException(org.hibernate.QueryException) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 27 with QueryException

use of org.hibernate.QueryException in project hibernate-orm by hibernate.

the class BulkManipulationTest method testDeleteNonExistentEntity.

@Test
public void testDeleteNonExistentEntity() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    try {
        s.createQuery("delete NonExistentEntity").executeUpdate();
        fail("no exception thrown");
    } catch (IllegalArgumentException e) {
        assertTyping(QueryException.class, e.getCause());
    } catch (QueryException ignore) {
    }
    t.commit();
    s.close();
}
Also used : QueryException(org.hibernate.QueryException) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 28 with QueryException

use of org.hibernate.QueryException in project hibernate-orm by hibernate.

the class BulkManipulationTest method testIncorrectSyntax.

@Test
public void testIncorrectSyntax() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    try {
        s.createQuery("update Human set Human.description = 'xyz' where Human.id = 1 and Human.description is null");
        fail("expected failure");
    } catch (IllegalArgumentException e) {
        assertTyping(QueryException.class, e.getCause());
    } catch (QueryException expected) {
    // ignore : expected behavior
    }
    t.commit();
    s.close();
}
Also used : QueryException(org.hibernate.QueryException) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 29 with QueryException

use of org.hibernate.QueryException in project hibernate-orm by hibernate.

the class BulkManipulationTest method testInsertWithMismatchedTypes.

@Test
public void testInsertWithMismatchedTypes() {
    TestData data = new TestData();
    data.prepare();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    try {
        s.createQuery("insert into Pickup (owner, vin, id) select id, vin, owner from Car").executeUpdate();
        fail("mismatched types did not error");
    } catch (IllegalArgumentException e) {
        assertTyping(QueryException.class, e.getCause());
    } catch (QueryException e) {
    // expected result
    }
    t.commit();
    t = s.beginTransaction();
    s.createQuery("delete Vehicle").executeUpdate();
    t.commit();
    s.close();
    data.cleanup();
}
Also used : QueryException(org.hibernate.QueryException) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 30 with QueryException

use of org.hibernate.QueryException in project hibernate-orm by hibernate.

the class BulkManipulationTest method testInsertAcrossMappedJoinFails.

@Test
public void testInsertAcrossMappedJoinFails() {
    TestData data = new TestData();
    data.prepare();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    try {
        s.createQuery("insert into Joiner (name, joinedName) select vin, owner from Car").executeUpdate();
        fail("mapped-join insertion did not error");
    } catch (IllegalArgumentException e) {
        assertTyping(QueryException.class, e.getCause());
    } catch (QueryException e) {
    // expected result
    }
    t.commit();
    t = s.beginTransaction();
    s.createQuery("delete Joiner").executeUpdate();
    s.createQuery("delete Vehicle").executeUpdate();
    t.commit();
    s.close();
    data.cleanup();
}
Also used : QueryException(org.hibernate.QueryException) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

QueryException (org.hibernate.QueryException)77 Type (org.hibernate.type.Type)20 Test (org.junit.Test)19 Session (org.hibernate.Session)18 Transaction (org.hibernate.Transaction)12 JoinType (org.hibernate.sql.JoinType)12 Queryable (org.hibernate.persister.entity.Queryable)10 CollectionType (org.hibernate.type.CollectionType)10 MappingException (org.hibernate.MappingException)9 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)9 AssociationType (org.hibernate.type.AssociationType)8 HashMap (java.util.HashMap)6 HibernateException (org.hibernate.HibernateException)6 JoinSequence (org.hibernate.engine.internal.JoinSequence)6 EntityType (org.hibernate.type.EntityType)6 AST (antlr.collections.AST)5 Map (java.util.Map)5 SemanticException (antlr.SemanticException)4 ArrayList (java.util.ArrayList)4 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)4