For those of you who are (like me) stuck with Oracle 9i release 1:
the final solution I found for this problem consists of creating a custom type to replace Hibernate's FloatType. The only difference is that instead of using setFloat it uses setDouble in the set method. In your mappings you have to replace type="float" with type="util.customHibernateTypes.FloatOra9i_r1"
Code:
/*
* FloatOra9i_r1.java
*
* Created on 20 de abril de 2005, 05:41 PM
*/
package util.customHibernateTypes;
import net.sf.hibernate.Hibernate;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import net.sf.hibernate.type.PrimitiveType;
/**
* This class is identical to net.sf.hibernate.type.FloatType, the only
* difference is that instead of using setFloat(int, float) it uses
* setDouble(int, double).
* The sole reason for it's existence is that JDBC drivers for Oracle's
* 9i release 1 database has a bug which removes the decimal part of
* float variables.
* @author jjsilo
*/
public class FloatOra9i_r1 extends PrimitiveType {
public Object get(ResultSet rs, String name) throws SQLException {
return new Float( rs.getFloat(name) );
}
public Class getPrimitiveClass() {
return float.class;
}
public Class getReturnedClass() {
return Float.class;
}
public void set(PreparedStatement st, Object value, int index)
throws SQLException {
st.setDouble( index, ( (Float) value ).floatValue() );
}
public int sqlType() {
return Types.FLOAT;
}
public String getName() { return "float"; }
public String objectToSQLString(Object value) throws Exception {
return value.toString();
}
public Object fromStringValue(String xml) {
return new Float(xml);
}
}