[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4443?page=c...
]
Chris Webb commented on HHH-4443:
---------------------------------
It would be useful if the new interface method
ResultSetIdentifierConsumer.consumeIdentifier(ResultSet resultSet) could throw an
SQLException.
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.0-Beta-2
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(a)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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira