java.util.Calendar conversion to java.util.Date fails

Description

When using java.util.Calendar in a query to retrieve an entity class containing a field of java.util.Date type it throws exceptions.

The same code worked fine in EAP 5 with Hibernate 3.
Here are the code snippets:

I've checked the hibernate source code.
In hibernate-entitymanager-3.4.0.GA-CP04(eap 5.1.2), I find the following code that seems to allow both java.util.Date and java.util.Calendar to work.
org.hibernate.ejb.QueryImpl.java:
public Query setParameter(String name, Date value, TemporalType temporalType);
public Query setParameter(String name, Calendar value, TemporalType temporalType);
The similar code still exists in hibernate-entitymanager-4.2.0.SP1-redhat-1 in org.hibernate.ejb.QueryImpl. However, it adds call to
registerParameterBinding( getParameter(name), value );
which in turns calls
private void validateParameterBinding(Parameter parameter, Object value)
in org.hibernate.ejb.AbstractQueryImpl:

Is this the expected behavior? Any reason we make such change?
I've also checked the JPA spec 2.0. It doesn't mention that java.util.Calendar should work with java.util.Date field or vice visa. It only mentions that the java.util.Date and java.util.Calendar should be supported for TemporalType.TIMESTAMP in "11.1.47 Temporal Annotation".

Environment

None

Assignee

Brett Meyer

Reporter

Gary Hu

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure