-->
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.  [ 2 posts ] 
Author Message
 Post subject: TINYINT UNSIGNED Problem, Hibernate or JDBC Driver ?
PostPosted: Thu Jul 20, 2006 6:30 am 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Hibernate 3.1.3, MySQL 4.0.x, MySQL JDBC Driver 3.1.13

The exception during a hsession.get() is:
Caused by: java.sql.SQLException: '128' in column '9' is outside valid range for the datatype TINYINT.

My table datatype is "TINYINT UNSIGNED" which on MySQL has a range of 0 to 255. It is true that if my datatype did not have the UNSIGNED part it would have a range of -128 to 127, making 128 outside the valid range.

My POJO looks like this:

Code:
public class Foobar {
private short dataValue;

public void setDataValue(short dataValue) {
  if(dataValue < 0 || dataValue > 255)
   return;
  this.dataValue = dataValue;
}
public short getDataValue() {
  return this.dataValue;
}
}

The mapping looks like this:
<property  name="dataValue"  type="short"  column="data_value" />


I have upgraded both Hibernate form 3.1.2 to 3.1.3 recently and the MySQL driver, since this code was last confirmed working.

Are SQLException's only ever generated from JDBC drivers ? If so this problem is with my JDBC driver ?

I am expecting Hibernate to call the JDBC getShort() function to get the value for the TINYINT UNSIGNED value.


Top
 Profile  
 
 Post subject: Java does not support unsigned types
PostPosted: Thu Oct 09, 2008 12:56 pm 
Beginner
Beginner

Joined: Mon Jul 28, 2008 4:36 pm
Posts: 24
It's Java that does not support unsigned types.

"All integral types represent signed numbers, there is no 'unsigned' keyword as there is in C and C++... When doing integer arithmetic, you simply must ensure that the type you are using has a sufficient range for the purposes you intend."
Source: Java in a Nutshell, 3rd Edition, by David Flanagan, Pub. O'Reilly, pp. 24-25

http://forum.hibernate.org/viewtopic.php?p=2397200

_________________
_____________________
-Glen


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.