use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class SQLExceptionConversionTest method testIntegrityViolation.
@Test
@SkipForDialect(value = { MySQLMyISAMDialect.class, AbstractHANADialect.class }, comment = "MySQL (MyISAM) / Hana do not support FK violation checking")
public void testIntegrityViolation() throws Exception {
final Session session = openSession();
session.beginTransaction();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
// Attempt to insert some bad values into the T_MEMBERSHIP table that should
// result in a constraint violation
PreparedStatement ps = null;
try {
ps = ((SessionImplementor) session).getJdbcCoordinator().getStatementPreparer().prepareStatement("INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)");
// Non-existent user_id
ps.setLong(1, 52134241);
// Non-existent group_id
ps.setLong(2, 5342);
((SessionImplementor) session).getJdbcCoordinator().getResultSetReturn().executeUpdate(ps);
fail("INSERT should have failed");
} catch (ConstraintViolationException ignore) {
// expected outcome
} finally {
releaseStatement(session, ps);
}
}
});
session.getTransaction().rollback();
session.close();
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class SequenceGeneratorTest method testStartOfSequence.
/**
* This seems a little trivial, but we need to guarantee that all Dialects start their sequences on a non-0 value.
*/
@Test
@TestForIssue(jiraKey = "HHH-8814")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
@SkipForDialect(value = SQLServer2012Dialect.class, comment = "SQLServer2012Dialect initializes sequence to minimum value (e.g., Long.MIN_VALUE; Hibernate assumes it is uninitialized.")
public void testStartOfSequence() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
final Person person = new Person();
s.persist(person);
tx.commit();
s.close();
assertTrue(person.getId() > 0);
assertTrue(sqlStatementInterceptor.getSqlQueries().stream().filter(sql -> sql.contains("product_sequence")).findFirst().isPresent());
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class ScrollableCollectionFetchingTest method testScrollingJoinFetchesPositioning.
@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with" + "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
@SkipForDialect(value = AbstractHANADialect.class, comment = "HANA only supports forward-only cursors.")
public void testScrollingJoinFetchesPositioning() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction txn = s.beginTransaction();
ScrollableResults results = s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").scroll();
results.first();
Animal animal = (Animal) results.get(0);
assertEquals("first() did not return expected row", data.root1Id, animal.getId());
results.scroll(1);
animal = (Animal) results.get(0);
assertEquals("scroll(1) did not return expected row", data.root2Id, animal.getId());
results.scroll(-1);
animal = (Animal) results.get(0);
assertEquals("scroll(-1) did not return expected row", data.root1Id, animal.getId());
results.setRowNumber(1);
animal = (Animal) results.get(0);
assertEquals("setRowNumber(1) did not return expected row", data.root1Id, animal.getId());
results.setRowNumber(2);
animal = (Animal) results.get(0);
assertEquals("setRowNumber(2) did not return expected row", data.root2Id, animal.getId());
txn.commit();
s.close();
data.cleanup();
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class ScrollableCollectionFetchingTest method testScrollingJoinFetchesSingleRowResultSet.
@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with" + "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
@SkipForDialect(value = AbstractHANADialect.class, comment = "HANA only supports forward-only cursors")
public void testScrollingJoinFetchesSingleRowResultSet() {
Session s = openSession();
Transaction txn = s.beginTransaction();
Animal mother = new Animal();
mother.setDescription("root-1");
Animal daughter = new Animal();
daughter.setDescription("daughter");
daughter.setMother(mother);
mother.addOffspring(daughter);
s.save(mother);
s.save(daughter);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
assertNotNull(s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").uniqueResult());
ScrollableResults results = s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").scroll();
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.previous());
assertTrue(results.next());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.next());
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertTrue(results.previous());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.previous());
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertTrue(results.next());
assertTrue(results.isFirst());
assertTrue(results.isLast());
results.beforeFirst();
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.previous());
assertTrue(results.first());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.next());
results.afterLast();
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.next());
assertTrue(results.last());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.next());
assertTrue(results.first());
assertTrue(results.isFirst());
assertTrue(results.isLast());
for (int i = 1; i < 3; i++) {
assertTrue(results.setRowNumber(1));
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.scroll(i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertTrue(results.setRowNumber(1));
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.scroll(-i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
if (i != 1) {
assertFalse(results.setRowNumber(i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.setRowNumber(-i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
}
}
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
s.createQuery("delete Animal where not description like 'root%'").executeUpdate();
s.createQuery("delete Animal").executeUpdate();
txn.commit();
s.close();
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class ClobLocatorTest method testBoundedClobLocatorAccess.
@Test
@SkipForDialect(value = TeradataDialect.class, jiraKey = "HHH-6637", comment = "Teradata requires locator to be used in same session where it was created/retrieved")
public void testBoundedClobLocatorAccess() throws Throwable {
String original = buildString(CLOB_SIZE, 'x');
String changed = buildString(CLOB_SIZE, 'y');
String empty = "";
Session s = openSession();
s.beginTransaction();
LobHolder entity = new LobHolder();
entity.setClobLocator(s.getLobHelper().createClob(original));
s.save(entity);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = s.get(LobHolder.class, entity.getId());
assertEquals(CLOB_SIZE, entity.getClobLocator().length());
assertEquals(original, extractData(entity.getClobLocator()));
s.getTransaction().commit();
s.close();
// test mutation via setting the new clob data...
if (getDialect().supportsLobValueChangePropogation()) {
s = openSession();
s.beginTransaction();
entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
entity.getClobLocator().truncate(1);
entity.getClobLocator().setString(1, changed);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
assertNotNull(entity.getClobLocator());
assertEquals(CLOB_SIZE, entity.getClobLocator().length());
assertEquals(changed, extractData(entity.getClobLocator()));
entity.getClobLocator().truncate(1);
entity.getClobLocator().setString(1, original);
s.getTransaction().commit();
s.close();
}
// test mutation via supplying a new clob locator instance...
s = openSession();
s.beginTransaction();
entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
assertNotNull(entity.getClobLocator());
assertEquals(CLOB_SIZE, entity.getClobLocator().length());
assertEquals(original, extractData(entity.getClobLocator()));
entity.setClobLocator(s.getLobHelper().createClob(changed));
s.getTransaction().commit();
s.close();
// test empty clob
if (!(getDialect() instanceof SybaseASE157Dialect)) {
// Skip for Sybase. HHH-6425
s = openSession();
s.beginTransaction();
entity = s.get(LobHolder.class, entity.getId());
assertEquals(CLOB_SIZE, entity.getClobLocator().length());
assertEquals(changed, extractData(entity.getClobLocator()));
entity.setClobLocator(s.getLobHelper().createClob(empty));
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
entity = s.get(LobHolder.class, entity.getId());
if (entity.getClobLocator() != null) {
assertEquals(empty.length(), entity.getClobLocator().length());
assertEquals(empty, extractData(entity.getClobLocator()));
}
s.delete(entity);
s.getTransaction().commit();
s.close();
}
}
Aggregations