[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2992) ID generator does not work for objects of type Byte

Wallace Wadge (JIRA) noreply at atlassian.com
Wed Dec 5 10:14:56 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2992?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29058 ] 

Wallace Wadge commented on HHH-2992:
------------------------------------

Scratch my last comment. The same problem holds, except that by now I've actually tested the patch (about to attach the entire file, just added the Byte(..) stuff and the code is so short it's a drop in replacement.)


> 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: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list