use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class NotFoundIgnoreOneToOneTest method testQueryImplicitPathDereferencePredicate.
@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "Bad results due to cross-join")
public void testQueryImplicitPathDereferencePredicate(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
final String hql = "select c from Coin c where c.currency.id = 1";
final List<Coin> coins = session.createQuery(hql, Coin.class).getResultList();
assertThat(coins).hasSize(1);
assertThat(coins.get(0).getCurrency()).isNull();
// technically we could use a subsequent-select rather than a join...
assertThat(statementInspector.getSqlQueries()).hasSize(1);
assertThat(statementInspector.getSqlQueries().get(0)).contains(" join ");
assertThat(statementInspector.getSqlQueries().get(0)).doesNotContain(" inner ");
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class NotFoundExceptionManyToOneTest method testGet.
@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "ObjectNotFoundException is thrown but caught and null is returned - see " + "org.hibernate.internal.SessionImpl.IdentifierLoadAccessImpl#doLoad")
public void testGet(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
try {
// should fail here loading the Coin due to missing currency (see NOTE#1)
session.get(Coin.class, 1);
fail("Expecting ObjectNotFoundException for broken fk");
} catch (ObjectNotFoundException expected) {
// technically we could use a subsequent-select rather than a join...
assertThat(statementInspector.getSqlQueries()).hasSize(1);
assertThat(statementInspector.getSqlQueries().get(0)).contains(" join ");
assertThat(statementInspector.getSqlQueries().get(0)).doesNotContain(" inner ");
assertThat(expected.getEntityName()).isEqualTo(Currency.class.getName());
assertThat(expected.getIdentifier()).isEqualTo(1);
}
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class NotFoundExceptionManyToOneTest method testQueryImplicitPathDereferencePredicate.
@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "EntityNotFoundException thrown rather than ObjectNotFoundException; " + "ObjectNotFoundException is thrown but caught and then converted to EntityNotFoundException")
public void testQueryImplicitPathDereferencePredicate(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
final String hql = "select c from Coin c where c.currency.id = 1";
try {
session.createQuery(hql, Coin.class).getResultList();
fail("Expecting ObjectNotFoundException for broken fk");
} catch (ObjectNotFoundException expected) {
assertThat(statementInspector.getSqlQueries()).hasSize(1);
assertThat(statementInspector.getSqlQueries().get(0)).contains(" join ");
assertThat(statementInspector.getSqlQueries().get(0)).doesNotContain(" inner ");
assertThat(expected.getEntityName()).isEqualTo(Currency.class.getName());
assertThat(expected.getIdentifier()).isEqualTo(1);
}
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class NativeSQLQueriesTest method testCompositeIdJoins.
@Test
@SuppressWarnings({ "unchecked" })
@FailureExpected(jiraKey = "unknown")
public void testCompositeIdJoins(SessionFactoryScope scope) {
scope.inTransaction(session -> {
Person person = new Person();
person.setName("Noob");
Product product = new Product();
product.setProductId(new Product.ProductId());
product.getProductId().setOrgid("x");
product.getProductId().setProductnumber("1234");
product.setName("Hibernate 3");
Order order = new Order();
order.setOrderId(new Order.OrderId());
order.getOrderId().setOrdernumber("1");
order.getOrderId().setOrgid("y");
product.getOrders().add(order);
order.setProduct(product);
order.setPerson(person);
session.save(product);
session.save(order);
session.save(person);
});
scope.inTransaction(session -> {
Product p = (Product) session.createQuery("from Product p join fetch p.orders").list().get(0);
assertTrue(Hibernate.isInitialized(p.getOrders()));
});
scope.inTransaction(session -> {
Object[] o = (Object[]) session.createNativeQuery("select\r\n" + " product.orgid as {product.id.orgid}," + " product.productnumber as {product.id.productnumber}," + " {prod_orders}.orgid as orgid3_1_,\r\n" + " {prod_orders}.ordernumber as ordernum2_3_1_,\r\n" + " product.name as {product.name}," + " {prod_orders.element.*}" + /*" orders.PROD_NO as PROD4_3_1_,\r\n" +
" orders.person as person3_1_,\r\n" +
" orders.PROD_ORGID as PROD3_0__,\r\n" +
" orders.PROD_NO as PROD4_0__,\r\n" +
" orders.orgid as orgid0__,\r\n" +
" orders.ordernumber as ordernum2_0__ \r\n" +*/
"from\r\n" + " Product product \r\n" + " inner join\r\n" + " TBL_ORDER {prod_orders} \r\n" + " on product.orgid={prod_orders}.PROD_ORGID \r\n" + " and product.productnumber={prod_orders}.PROD_NO").addEntity("product", Product.class).addJoin("prod_orders", "product.orders").list().get(0);
Product p = (Product) o[0];
assertTrue(Hibernate.isInitialized(p.getOrders()));
assertNotNull(p.getOrders().iterator().next());
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class MappedSuperclassType2Test method testMappedSuperclassAccessNoEntity.
@Test
@TestForIssue(jiraKey = "HHH-8534")
@FailureExpected(jiraKey = "HHH-8534")
public void testMappedSuperclassAccessNoEntity() {
// stupid? yes. tck does it? yes.
final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {
@Override
public List<String> getManagedClassNames() {
// pass in a MappedSuperclass that is not used in any entity hierarchy
return Arrays.asList(SomeMappedSuperclass.class.getName());
}
};
final Map settings = new HashMap();
settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
try {
ManagedType<SomeMappedSuperclass> type = emf.getMetamodel().managedType(SomeMappedSuperclass.class);
// the issue was in regards to throwing an exception, but also check for nullness
assertNotNull(type);
} finally {
emf.close();
}
}
Aggregations