[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-4443) Allow generic handling of any Hibernate type for post-insert generated identifiers
Steve Ebersole (JIRA)
noreply at atlassian.com
Thu Oct 22 17:23:32 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4443?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Steve Ebersole closed HHH-4443.
-------------------------------
Resolution: Fixed
> Allow generic handling of any Hibernate type for post-insert generated identifiers
> ----------------------------------------------------------------------------------
>
> Key: HHH-4443
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4443
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core
> Reporter: Steve Ebersole
> Assignee: Steve Ebersole
> Fix For: 3.5
>
>
> See HB-92 for the original request. Much of the discussion unfortunately occurred in a private email thread with the original requester, but here is the proposed solution:
> Steve Ebersole <steve at hibernate.org> wrote:
> The "more correct" solution is along the lines a contract to allow the
> type to handle this like you said. I'm thinking something like an
> optional interface for the type to publish that fact:
>
> public interface ResultSetIdentifierConsumer {
> public Serializable consumeIdentifier(ResultSet resultSet);
> }
>
> then IdentifierGeneratorFactory (called IdentifierGeneratorHelper now
> btw) can say:
>
> public static Serializable get(ResultSet rs, Type type) ... {
> if ( type instanceof ResultSetIdentifierConsumer ) {
> return ( ( ResultSetIdentifierConsumer ) type ).consumeIdentifier( rs );
> }
>
> 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 {
>
> throw ...
> }
> }
> and you can define a type :
>
> public class MyCustomLongIdType ... implements ResultSetIdentifierConsumer ... {
> public Serializable consumeIdentifier(ResultSet resultSet) {
> return new MyCustomLongId( resultSet.getLong( 1 ) );
> }
> ...
> }
--
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