[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5803) ValueHandlerFactory fails to convert from java.lang.Long to java.lang.Number

Jens Rydholm (JIRA) noreply at atlassian.com
Tue Dec 21 07:18:05 EST 2010


ValueHandlerFactory fails to convert from java.lang.Long to java.lang.Number
----------------------------------------------------------------------------

                 Key: HHH-5803
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5803
             Project: Hibernate Core
          Issue Type: Bug
          Components: entity-manager, query-criteria
    Affects Versions: 3.6.0
         Environment: Hibernate 3.6.0, Microsoft SQL Server 2008 R2
            Reporter: Jens Rydholm


When using the criteria builder to compare the quotient between two database columns with a Long value from the Java code, Hibernate is unaware of how to convert from a Long to a Number (despite Long being a subclass of Number). Pseudocode and exception stacktrace included below.

CriteriaBuilder builder = ...;
Path<Long> longPath = ...;
Path<Float> floatPath = ...;
Long aLong = 250000000L;
builder.ge(builder.quot(longPath, floatPath), aLong);

java.lang.IllegalArgumentException: Unaware how to convert value [250000000 : java.lang.Long] to requested type [java.lang.Number]
        at org.hibernate.ejb.criteria.ValueHandlerFactory.unknownConversion(ValueHandlerFactory.java:259)
        at org.hibernate.ejb.criteria.ValueHandlerFactory.convert(ValueHandlerFactory.java:287)
        at org.hibernate.ejb.criteria.predicate.ComparisonPredicate.<init>(ComparisonPredicate.java:88)
        at org.hibernate.ejb.criteria.CriteriaBuilderImpl.ge(CriteriaBuilderImpl.java:534)
...

Can be worked around by using builder.toLong to wrap builder.quot, like this:
builder.ge(builder.toLong(builder.quot(longPath, floatPath)), aLong);

Due to time constraints and the existing workaround, a test case can unfortunately not be provided at this time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list