Hi,
I have a named query that used to work before 3.1. Here is the named query:
Code:
<query name="Scan.byUnreviewedStatus.withDuplicateScales">
<![CDATA[
select scan
from com.gemex.scan.Scan as scan
where scan.productPrefix = :productPrefix
and scan.id != :id
and scan.whiteLightRawValue > (:whiteLightRawValue - .0001)
and scan.whiteLightRawValue < (:whiteLightRawValue + .0001)
and scan.colorLightRawValue > (:colorLightRawValue - .0001)
and scan.colorLightRawValue < (:colorLightRawValue + .0001)
and scan.scintillationRawValue > (:scintillationRawValue - .0001)
and scan.scintillationRawValue < (:scintillationRawValue + .0001)
and (scan.scanStatusCode = :unreviewedScanStatusCode or scan.scanStatusCode = :skippedScanStatusCode)
]]>
</query>
After going to 3.1, I get an error that basically said it cannot set the value for parameter, whiteLightRawValue. When I checked the debug statement, it is trying to set the value as a DoubleType. However, the field, whiteLightRawValue, is actually a Float type.
Hibernate version: 3.1
Database and version: MySQL 5.0.16
Here is the code to set the parameter:
Code:
Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
try {
Query query = session.getNamedQuery("Scan.byUnreviewedStatus.withDuplicateScales");
query.setParameter("id", scan.getId());
query.setParameter("unreviewedScanStatusCode", unreviewedScanStatusCode);
query.setParameter("skippedScanStatusCode", skippedScanStatusCode);
query.setParameter("productPrefix", scan.getProductPrefix());
query.setFloat("whiteLightRawValue", scan.getWhiteLightRawValue());
query.setFloat("colorLightRawValue", scan.getColorLightRawValue());
query.setFloat("scintillationRawValue", scan.getScintillationRawValue());
unreviewedScansWithDuplicateScales = query.list();
return unreviewedScansWithDuplicateScales;
}
Here is the snippet of the mapping between the database column and the Java field:
Code:
<property name="whiteLightRawValue" type="java.lang.Float" >
<column name="WhiteLightRawValue" length="12" not-null="false" sql-type="float" />
</property>
If anyone need the entire mapping file or persistent class, I can provide them but they are rather long. Basically, the MySQL column for WhiteLightRawValue is defined as a float in MySQL and the mapped field in the persisent class is a Java Float.
One last thing, when I changed the code to explicitly set the parameter as a Float type (see below), then it works. But as I stated before, this worked before 3.1, so I am guessing that's a bug in 3.1?
Code:
query.setFloat("whiteLightRawValue", scan.getWhiteLightRawValue());
query.setFloat("colorLightRawValue", scan.getColorLightRawValue());
query.setFloat("scintillationRawValue", scan.getScintillationRawValue());
Thanks,
Ben