use of org.hibernate.testing.SkipForDialect in project hibernate-orm by hibernate.
the class QueryTest method testNullNamedParameter.
@Test
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNullNamedParameter() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
Query q = em.createQuery("from Item i where i.intVal=:iVal");
q.setParameter("iVal", null);
List results = q.getResultList();
// null != null
assertEquals(0, results.size());
q = em.createQuery("from Item i where i.intVal is null and :iVal is null");
q.setParameter("iVal", null);
results = q.getResultList();
assertEquals(1, results.size());
q = em.createQuery("from Item i where i.intVal is null or i.intVal = :iVal");
q.setParameter("iVal", 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.SkipForDialect in project hibernate-orm by hibernate.
the class QueryTest method testNullNamedParameterParameter.
@Test
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNullNamedParameterParameter() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
Query q = em.createQuery("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);
List results = q.getResultList();
// null != null
assertEquals(0, results.size());
q = em.createQuery("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.createQuery("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.SkipForDialect 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.SkipForDialect 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.SkipForDialect in project hibernate-orm by hibernate.
the class EntityTest method testTemporalType.
@Test
@SkipForDialect(value = Oracle10gDialect.class, comment = "oracle12c returns time in getDate. For now, skip.")
public void testTemporalType() throws Exception {
Flight airFrance = doInHibernate(this::sessionFactory, session -> {
Flight _airFrance = new Flight();
_airFrance.setId(Long.valueOf(747));
_airFrance.setName("Paris-Amsterdam");
_airFrance.setDuration(Long.valueOf(10));
_airFrance.setDepartureDate(Date.from(LocalDate.of(2005, 06, 21).atStartOfDay(ZoneId.systemDefault()).toInstant()));
_airFrance.setAlternativeDepartureDate(new GregorianCalendar(2006, 02, 03, 10, 00));
_airFrance.getAlternativeDepartureDate().setTimeZone(TimeZone.getTimeZone("GMT"));
_airFrance.setBuyDate(new java.sql.Timestamp(122367443));
_airFrance.setFactor(25);
session.persist(_airFrance);
return _airFrance;
});
doInHibernate(this::sessionFactory, session -> {
Query q = session.createQuery("from Flight f where f.departureDate = :departureDate");
q.setParameter("departureDate", airFrance.getDepartureDate(), StandardBasicTypes.DATE);
Flight copyAirFrance = (Flight) q.uniqueResult();
assertNotNull(copyAirFrance);
assertEquals(Date.from(LocalDate.of(2005, 06, 21).atStartOfDay(ZoneId.systemDefault()).toInstant()), copyAirFrance.getDepartureDate());
assertEquals(df.format(airFrance.getBuyDate()), df.format(copyAirFrance.getBuyDate()));
session.delete(copyAirFrance);
});
}
Aggregations