-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Float inserting issue
PostPosted: Mon Sep 13, 2004 9:03 am 
Newbie

Joined: Mon Sep 13, 2004 8:53 am
Posts: 1
[b]Hibernate version: 2.0[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Name and version of the database you are using: Oracle 9i (9.2.0.1.0)[/b]


I have a issue when I insert a float in a table. Hibernate seems to be cutting the floating part.
For instance, when I insert 15.12, 15 is actually inserted.
However, Hibernate can reach correctly a float that have been inserted manually.

To save my bean to my database I call the function save: session.save();

My mapping is for this column is:

<property
name="workAcc"
type="float"
update="true"
insert="true"
access="property"
column="WORK_ACC"
/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 9:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Of course this has nothing to do with Hibernate, it is happening somewhere else.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 2:53 pm 
Newbie

Joined: Thu Feb 24, 2005 3:51 pm
Posts: 9
Location: Montevideo, Uruguay
I'm having the same problem. Did you find a solution?

Thanks,
JJ


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 4:23 pm 
Newbie

Joined: Thu Feb 24, 2005 3:51 pm
Posts: 9
Location: Montevideo, Uruguay
Just as Gavin said, this isn't a Hibernate issue.
It's a known issue with JDBC drivers for Oracle 9i
http://www.hibernate.org/80.html


Top
 Profile  
 
 Post subject: For those stuck with Oracle 9i release 1
PostPosted: Wed Apr 20, 2005 5:59 pm 
Newbie

Joined: Thu Feb 24, 2005 3:51 pm
Posts: 9
Location: Montevideo, Uruguay
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);
   }
   
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.