]
Wallace Wadge commented on HHH-2992:
------------------------------------
Sorry,
Having tried to compile the code myself, I see the Serializable problem. At this point
I'm not sure if this issue should be marked as invalid. How would one map an ID marked
as TINYINT(3) in the DB?
Apologies for the noise on the list.
ID generator does not work for objects of type Byte
---------------------------------------------------
Key: HHH-2992
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2992
Project: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.2.5
Environment: Platform-independent, mysql db
Reporter: Wallace Wadge
Priority: Minor
The current ID generator code (org.hibernate.id.IdentifierGeneratorFactory) fails to take
into account objects of type Byte (according to the jdbc spec, a TINYINT may be mapped to
a Byte or Short - see
http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html)
The following code adds this support:
-----
// unhappy about this being public ... is there a better way?
public static Serializable get(ResultSet rs, Type type)
throws SQLException, IdentifierGenerationException {
Class clazz = type.getReturnedClass();
if ( clazz==Long.class ) {
return new Long( rs.getLong(1) );
}
else if ( clazz==Integer.class ) {
return new Integer( rs.getInt(1) );
}
else if ( clazz==Short.class ) {
return new Short( rs.getShort(1) );
}
else if ( clazz==String.class ) {
return rs.getString(1);
}
else if ( clazz==Byte.class ) {
return rs.getByte(1);
}
else {
throw new IdentifierGenerationException("this id generator generates long,
integer, short, byte or string");
}
}
-------------
I'm not sure if we need to add the same logic to the method createNumber in the same
file.
Regards.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: