use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.
the class NotFoundExceptionManyToOneTest method testQueryOwnerSelection.
@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "EntityNotFoundException thrown rather than ObjectNotFoundException; " + "ObjectNotFoundException is thrown but caught and then converted to EntityNotFoundException")
public void testQueryOwnerSelection(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
final String hql = "select c from Coin c";
try {
session.createQuery(hql, Coin.class).getResultList();
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 NotFoundIgnoreOneToOneTest 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 NotFoundIgnoreManyToOneTest method testQueryAssociationSelection.
@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "Has zero results because of inner-join; & the select w/ inner-join is executed twice for some odd reason")
public void testQueryAssociationSelection(SessionFactoryScope scope) {
final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
statementInspector.clear();
scope.inTransaction((session) -> {
final String hql = "select c.currency from Coin c";
session.createQuery(hql, Currency.class).getResultList();
final List<Currency> currencies = session.createSelectionQuery(hql, Currency.class).getResultList();
assertThat(currencies).hasSize(1);
assertThat(currencies.get(0)).isNull();
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 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.createSelectionQuery(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.JiraKey in project hibernate-orm by hibernate.
the class HANAStoredProcedureTest method testBindParameterAsHibernateType.
@Test
@JiraKey("HHH-12661")
public void testBindParameterAsHibernateType(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
StoredProcedureQuery query = session.createStoredProcedureQuery("sp_phone_validity").registerStoredProcedureParameter(1, NumericBooleanConverter.class, ParameterMode.IN).registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR).setParameter(1, true);
query.execute();
List<?> phones = query.getResultList();
assertEquals(1, phones.size());
assertEquals("123-456-7890", phones.get(0));
});
scope.inTransaction((session) -> {
Vote vote1 = new Vote();
vote1.setId(1L);
vote1.setVoteChoice(true);
session.persist(vote1);
Vote vote2 = new Vote();
vote2.setId(2L);
vote2.setVoteChoice(false);
session.persist(vote2);
});
scope.inTransaction((session) -> {
StoredProcedureQuery query = session.createStoredProcedureQuery("sp_votes").registerStoredProcedureParameter(1, YesNoConverter.class, ParameterMode.IN).registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR).setParameter(1, true);
query.execute();
List<?> votes = query.getResultList();
assertEquals(1, votes.size());
assertEquals(1, ((Number) votes.get(0)).intValue());
});
}
Aggregations