use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class NativeQueryOrdinalParametersTest method testNativeQueryOrdinalParameter.
@Test
@TestForIssue(jiraKey = "HHH-10885")
public void testNativeQueryOrdinalParameter() {
EntityManager em = getOrCreateEntityManager();
try {
Query query = em.createNativeQuery("SELECT * FROM GAME g WHERE title = ?");
query.setParameter(1, "Super Mario Brothers");
List list = query.getResultList();
assertEquals(1, list.size());
} finally {
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class NativeQueryOrdinalParametersTest method testNativeQueryIndexedOrdinalParameter.
@Test
@TestForIssue(jiraKey = "HHH-10885")
public void testNativeQueryIndexedOrdinalParameter() {
EntityManager em = getOrCreateEntityManager();
try {
Query query = em.createNativeQuery("SELECT * FROM GAME g WHERE title = ?1");
query.setParameter(1, "Super Mario Brothers");
List list = query.getResultList();
assertEquals(1, list.size());
} finally {
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testNativeQueryNullPositionalParameterParameter.
@Test
@TestForIssue(jiraKey = "HHH-10161")
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = Oracle8iDialect.class, comment = "ORA-00932: inconsistent datatypes: expected NUMBER got BINARY")
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNativeQueryNullPositionalParameterParameter() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
// native queries don't seem to flush by default ?!?
em.flush();
Query q = em.createNativeQuery("select * from Item i where i.intVal=?");
Parameter p = new Parameter() {
@Override
public String getName() {
return null;
}
@Override
public Integer getPosition() {
return 1;
}
@Override
public Class getParameterType() {
return Integer.class;
}
};
q.setParameter(p, null);
Parameter pGotten = q.getParameter(p.getPosition());
List results = q.getResultList();
// null != null
assertEquals(0, results.size());
q = em.createNativeQuery("select * from Item i where i.intVal is null and ? is null");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
q = em.createNativeQuery("select * from Item i where i.intVal is null or i.intVal = ?");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testNativeQueryNullNamedParameterParameter.
@Test
@TestForIssue(jiraKey = "HHH-10161")
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = Oracle8iDialect.class, comment = "ORA-00932: inconsistent datatypes: expected NUMBER got BINARY")
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNativeQueryNullNamedParameterParameter() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
// native queries don't seem to flush by default ?!?
em.flush();
Query q = em.createNativeQuery("select * 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 Integer.class;
}
};
q.setParameter(p, null);
Parameter pGotten = q.getParameter(p.getName());
List results = q.getResultList();
assertEquals(0, results.size());
q = em.createNativeQuery("select * 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.createNativeQuery("select * 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();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testNamedParameterWithUserError.
@Test
@TestForIssue(jiraKey = "HHH-10803")
public void testNamedParameterWithUserError() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Wallet w = new Wallet();
w.setBrand("Lacoste");
w.setModel("Minimic");
w.setSerial("0100202002");
em.persist(w);
em.flush();
Query jpaQuery = em.createQuery("select w from Wallet w");
try {
Parameter<?> parameter = jpaQuery.getParameter("brand");
fail("Should fail due to user error in parameters");
} catch (Exception e) {
assertTyping(IllegalArgumentException.class, e);
}
jpaQuery = em.createQuery("select w from Wallet w");
try {
Parameter<String> parameter = jpaQuery.getParameter("brand", String.class);
fail("Should fail due to user error in parameters");
} catch (Exception e) {
assertTyping(IllegalArgumentException.class, e);
}
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
Aggregations