use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class ManipulationCriteriaTest method testDeleteWithUnCorrelatedSubquery.
@Test
// MySQL does not allow "delete/update from" and subqueries to use the same table
@SkipForDialect(MySQLDialect.class)
public void testDeleteWithUnCorrelatedSubquery() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
// attempt to delete Customers who's age is less than the AVG age
CriteriaDelete<Customer> criteria = builder.createCriteriaDelete(Customer.class);
Root<Customer> customerRoot = criteria.from(Customer.class);
Subquery<Double> subCriteria = criteria.subquery(Double.class);
Root<Customer> subQueryCustomerRoot = subCriteria.from(Customer.class);
subCriteria.select(builder.avg(subQueryCustomerRoot.get(Customer_.age)));
// also illustrates the new capability to use the subquery selection as an expression!
criteria.where(builder.lessThan(customerRoot.get(Customer_.age), subCriteria.getSelection().as(Integer.class)));
// make sure Subquery#getParent fails...
try {
subCriteria.getParent();
fail("Expecting Subquery.getParent call to fail on DELETE containing criteria");
} catch (IllegalStateException expected) {
}
Query query = em.createQuery(criteria);
try {
// first, make sure an attempt to list fails
query.getResultList();
fail("Attempt to getResultList() on delete criteria should have failed");
} catch (IllegalStateException expected) {
}
query.executeUpdate();
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class CastTest method testCastToString.
@Test
@SkipForDialect(value = DerbyDialect.class, comment = "Derby does not support cast from INTEGER to VARCHAR")
@TestForIssue(jiraKey = "HHH-5755")
public void testCastToString() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Product product = new Product();
product.setId("product1");
product.setPrice(1.23d);
product.setQuantity(QUANTITY);
product.setPartNumber(((long) Integer.MAX_VALUE) + 1);
product.setRating(1.999f);
product.setSomeBigInteger(BigInteger.valueOf(987654321));
product.setSomeBigDecimal(BigDecimal.valueOf(987654.321));
em.persist(product);
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
Root<Product> root = criteria.from(Product.class);
criteria.where(builder.equal(root.get(Product_.quantity).as(String.class), builder.literal(String.valueOf(QUANTITY))));
List<Product> result = em.createQuery(criteria).getResultList();
Assert.assertEquals(1, result.size());
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
em.createQuery("delete Product").executeUpdate();
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testCorrelationExplicitSelectionCorrelation.
@Test
@SkipForDialect(value = SybaseASE15Dialect.class, jiraKey = "HHH-3032")
public void testCorrelationExplicitSelectionCorrelation() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Customer> customerCriteria = builder.createQuery(Customer.class);
Root<Customer> customer = customerCriteria.from(Customer.class);
Join<Customer, Order> o = customer.join(Customer_.orders);
Subquery<Order> sq = customerCriteria.subquery(Order.class);
Join<Customer, Order> sqo = sq.correlate(o);
Join<Order, LineItem> sql = sqo.join(Order_.lineItems);
sq.where(builder.gt(sql.get(LineItem_.quantity), 3));
// use the correlation itself as the subquery selection (initially caused problems wrt aliases)
sq.select(sqo);
customerCriteria.select(customer).distinct(true);
customerCriteria.where(builder.exists(sq));
em.createQuery(customerCriteria).getResultList();
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class LockTest method testContendedPessimisticLock.
@Test
@SkipForDialect(HSQLDialect.class)
// only.
@SkipForDialect(value = { SybaseASE15Dialect.class }, strictMatching = true, jiraKey = "HHH-6820")
public void testContendedPessimisticLock() throws Exception {
final EntityManager em = getOrCreateEntityManager();
final EntityManager isolatedEntityManager = createIsolatedEntityManager();
Lock lock = createAndPersistLockInstance(em);
try {
inFirstTransactionReloadAndModifyLockInstance(em, lock);
final CountDownLatch latch = new CountDownLatch(1);
FutureTask<Boolean> future = inBackgroundThreadStartSecondTransactionAndReadLockInstance(latch, isolatedEntityManager);
// wait with timeout on the background thread
log.debug("testContendedPessimisticLock: wait on BG thread");
boolean backGroundThreadCompleted = latch.await(3, TimeUnit.SECONDS);
if (backGroundThreadCompleted) {
// the background thread read a value. At the very least we need to assert that he did not see the
// changed value
boolean backgroundThreadHasReadNewValue = future.get();
assertFalse("The background thread is not allowed to see the updated value while the first transaction has not committed yet", backgroundThreadHasReadNewValue);
em.getTransaction().commit();
} else {
log.debug("The background thread was blocked");
// commit first transaction so that background thread can continue
em.getTransaction().commit();
boolean backgroundThreadHasReadNewValue = future.get();
assertTrue("Background thread should read the new value afterQuery being unblocked", backgroundThreadHasReadNewValue);
}
} finally {
cleanup(em, isolatedEntityManager, lock);
}
}
use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class QueryTest method testNullNamedParameterParameterIncompatible.
@Test
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNullNamedParameterParameterIncompatible() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
Query q = em.createQuery("from Item i where i.intVal=:iVal");
Parameter p = new Parameter() {
@Override
public String getName() {
return "iVal";
}
@Override
public Integer getPosition() {
return null;
}
@Override
public Class getParameterType() {
return Long.class;
}
};
q.setParameter(p, null);
List results = q.getResultList();
// null != null
assertEquals(0, results.size());
q = em.createQuery("from Item i where i.intVal is null and :iVal is null");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
q = em.createQuery("from Item i where i.intVal is null or i.intVal = :iVal");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
Aggregations