Cast fields to number via Java instead of in the query for Hibernate

This was breaking Hibernate's JPA implementation.

The tests were always passing since they use eclipselink's JPA implementation instead of Hibernate's.
Taken from the BlackLocus Edition of JPA-NestedSet. I think this fixes romanb/JPA-NestedSet#12.