use of org.hibernate.testing.TestForIssue 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.TestForIssue in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testCorrelatedJoinsFromSubquery.
@Test
@TestForIssue(jiraKey = "HHH-8556")
public void testCorrelatedJoinsFromSubquery() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
CriteriaQuery<Customer> cquery = builder.createQuery(Customer.class);
Root<Customer> customer = cquery.from(Customer.class);
cquery.select(customer);
Subquery<Order> sq = cquery.subquery(Order.class);
Join<Customer, Order> sqo = sq.correlate(customer.join(Customer_.orders));
sq.select(sqo);
Set<Join<?, ?>> cJoins = sq.getCorrelatedJoins();
// ensure the join is returned in #getCorrelatedJoins
assertEquals(cJoins.size(), 1);
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class CriteriaLiteralInSelectExpressionTest method testNullLiteral.
@Test
@TestForIssue(jiraKey = "HHH-10861")
public void testNullLiteral() throws Exception {
final EntityManager entityManager = getOrCreateEntityManager();
try {
entityManager.getTransaction().begin();
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<MyEntityDTO> query = criteriaBuilder.createQuery(MyEntityDTO.class);
final Root<MyEntity> entity = query.from(MyEntity.class);
query.multiselect(criteriaBuilder.literal(false), criteriaBuilder.nullLiteral(String.class));
final List<MyEntityDTO> dtos = entityManager.createQuery(query).getResultList();
assertThat(dtos.size(), is(1));
assertThat(dtos.get(0).active, is(false));
assertThat(dtos.get(0).name, nullValue());
assertThat(dtos.get(0).surname, nullValue());
entityManager.getTransaction().commit();
} catch (Exception e) {
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().rollback();
}
throw e;
} finally {
entityManager.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class NullLiteralExpression method testNullLiteralExpressionInCriteriaUpdate.
@Test
@TestForIssue(jiraKey = "HHH-11159")
public void testNullLiteralExpressionInCriteriaUpdate() {
EntityManager entityManager = getOrCreateEntityManager();
try {
entityManager.getTransaction().begin();
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaUpdate<Person> criteriaUpdate = builder.createCriteriaUpdate(Person.class);
criteriaUpdate.from(Person.class);
criteriaUpdate.set(Person_.subject, builder.nullLiteral(Subject.class));
entityManager.createQuery(criteriaUpdate).executeUpdate();
entityManager.getTransaction().commit();
} catch (Exception e) {
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().rollback();
}
throw e;
} finally {
entityManager.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class FlushTest method testFlushOnDetached.
@Test
@TestForIssue(jiraKey = "EJBTHREE-722")
public void testFlushOnDetached() throws Exception {
EntityManager manager = getOrCreateEntityManager();
manager.getTransaction().begin();
Pet p1 = createCat("Toonses", 15.0, 9, manager);
manager.flush();
manager.clear();
Pet p2 = createCat("Sox", 10.0, 5, manager);
manager.flush();
manager.clear();
Pet p3 = createDog("Winnie", 70.0, 5, manager);
manager.flush();
manager.clear();
Pet p4 = createDog("Junior", 11.0, 1, manager);
manager.flush();
manager.clear();
Decorate d1 = createDecorate("Test", p1, manager);
manager.flush();
manager.clear();
Decorate d2 = createDecorate("Test2", p2, manager);
manager.flush();
manager.clear();
List l = findByWeight(14.0, manager);
manager.flush();
manager.clear();
for (Object o : l) {
Assert.assertTrue(names.contains(((Pet) o).getName()));
}
Collection<Decorate> founds = getDecorate(manager);
manager.flush();
manager.clear();
for (Decorate value : founds) {
Assert.assertTrue(names.contains(value.getPet().getName()));
}
manager.getTransaction().rollback();
manager.close();
}
Aggregations