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

Wallace Wadge (JIRA) noreply at atlassian.com
Thu Dec 6 03:06:58 EST 2007


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

Wallace Wadge updated HHH-2992:
-------------------------------

    Attachment: test.sql

SQL script attached

> 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
>         Attachments: IdentifierGeneratorFactory.java, test.sql, testCaseCompleteWithJars.zip, testcaseEclipseProject.zip
>
>
> 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