use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.
the class NotFoundIgnoreManyToOneTest method testQueryOwnerSelection.
@Test
@JiraKey("HHH-15060")
public void testQueryOwnerSelection(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
final String hql = "select c from Coin c";
final List<Coin> coins = session.createSelectionQuery(hql, Coin.class).getResultList();
assertThat(coins).hasSize(1);
assertThat(coins.get(0).getCurrency()).isNull();
// at the moment this uses a subsequent-select. on the bright side, it is at least eagerly fetched.
assertThat(statementInspector.getSqlQueries()).hasSize(2);
assertThat(statementInspector.getSqlQueries().get(0)).contains(" from Coin ");
assertThat(statementInspector.getSqlQueries().get(1)).contains(" from Currency ");
// but I believe a jon would be better
// 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.JiraKey in project hibernate-orm by hibernate.
the class NotFoundIgnoreManyToOneTest method testGet.
@Test
@JiraKey("HHH-15060")
public void testGet(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
final Coin coin = session.get(Coin.class, 1);
assertThat(coin.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.JiraKey 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.JiraKey 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.JiraKey in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testCorrelationExplicitSelectionCorrelation.
@Test
@JiraKey("HHH-3032")
@SkipForDialect(dialectClass = SybaseASEDialect.class, majorVersion = 15)
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();
}
Aggregations