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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations