IMO this issue covers some more problems with
public interface Query {
<T> Query setParameter(Parameter<T> param, T value);
First, as mentioned above contains(), does not work, because of missing hashCode() and equals() for QueryImpl$ParameterImpl.
Second, after you have fixed the problem, you can see, the type is not used:
public class QueryImpl<X> extends org.hibernate.ejb.AbstractQueryImpl<X> implements TypedQuery<X>, HibernateQuery {
public <T> TypedQuery<X> setParameter(Parameter<T> param, T value) {
if ( ! parameters.contains( param ) ) {
throw new IllegalArgumentException( "Specified parameter was not found in query" );
}
if ( param.getName() != null ) {
setParameter( param.getName(), value );
}
else {
setParameter( param.getPosition(), value );
}
return this;
}
This works fine, when Hibernate can retrieve the parameter type from the query. However this is not always possible. E.g.: ... where coalesce(birthDate,sysdate) = coalesce(:birthDate,sysdate)
With Hibernate and Oracle, this produces a ORA-01465. Simple workaround with Hibernate instead of JPA:
TypedQuery<Person> tq = em.createNamedQuery(...)
Query query = tq.unwrap(QueryImpl.class).getHibernateQuery();
query.setTimestamp("birthDate", birthDate);
IMHO, the implementation of setParameter(Parameter<T> param, T value) is more or less missing.
|