use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class CoalesceTest method HHH_10463_NullInCoalesce_PostgreSQL_Workaround.
@Test
@RequiresDialect(PostgreSQL81Dialect.class)
public void HHH_10463_NullInCoalesce_PostgreSQL_Workaround() {
doInHibernate(this::sessionFactory, session -> {
Query query = session.createQuery("from Person p where p.name = coalesce(cast( :name as string) , p.name) ");
query.setParameter("name", null);
List<Person> resultList = query.getResultList();
assertThat(resultList, hasItem(person));
});
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class UUIDBasedIdInterpretationTest method testBinaryRuntimeUsage.
@Test
@TestForIssue(jiraKey = "HHH-10564")
@RequiresDialect(H2Dialect.class)
public void testBinaryRuntimeUsage() {
StandardServiceRegistry ssr = buildStandardServiceRegistry(H2Dialect.class, true);
try {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UuidIdEntity.class).buildMetadata();
final SessionFactory sf = metadata.buildSessionFactory();
try {
Session s = sf.openSession();
try {
s.beginTransaction();
s.byId(UuidIdEntity.class).load(UUID.randomUUID());
s.getTransaction().commit();
} finally {
s.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class SQLServer2012SequenceGeneratorTest method testStartOfSequence.
/**
* SQL server requires that sequence be initialized to something other than the minimum value for the type
* (e.g., Long.MIN_VALUE). For generator = "sequence", the initial value must be provided as a parameter.
* For this test, the sequence is initialized to 10.
*/
@Test
@TestForIssue(jiraKey = "HHH-8814")
@RequiresDialect(value = SQLServer2012Dialect.class)
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() == 10);
s = openSession();
tx = s.beginTransaction();
s.createQuery("delete from Person").executeUpdate();
tx.commit();
s.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class FooBarTest method testUserProvidedConnection.
@Test
@RequiresDialect(value = H2Dialect.class, comment = "this is more like a unit test")
public void testUserProvidedConnection() throws Exception {
ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
Session s = sessionFactory().withOptions().connection(dcp.getConnection()).openSession();
Transaction tx = s.beginTransaction();
s.createQuery("from Fo").list();
tx.commit();
Connection c = s.disconnect();
assertTrue(c != null);
s.reconnect(c);
tx = s.beginTransaction();
s.createQuery("from Fo").list();
tx.commit();
c.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class PessimisticWriteLockTimeoutTest method testNoWait.
@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL81Dialect.class, SQLServer2005Dialect.class })
public void testNoWait() throws NoSuchFieldException, IllegalAccessException {
Session session = sessionFactory().openSession();
session.beginTransaction();
try {
session.createQuery("select a from A a", A.class).unwrap(org.hibernate.query.Query.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.NO_WAIT)).list();
String lockingQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertTrue(lockingQuery.toLowerCase().contains("nowait"));
} finally {
session.getTransaction().commit();
session.close();
}
}
Aggregations