[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7234) No way to get Object's type in nullSafeGet
Vagif Kuliyev (JIRA)
noreply at atlassian.com
Tue Apr 10 01:34:51 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-7234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46211#comment-46211 ]
Vagif Kuliyev commented on HHH-7234:
------------------------------------
My preferred SerA implementation is using ProtoStuff but Kryo also requires the class to deserialize.
> No way to get Object's type in nullSafeGet
> ------------------------------------------
>
> Key: HHH-7234
> URL: https://hibernate.onjira.com/browse/HHH-7234
> Project: Hibernate ORM
> Issue Type: New Feature
> Components: core
> Affects Versions: 4.1.0
> Reporter: Vagif Kuliyev
>
> I am trying to do the following:
> public class SerUserType extends MutableUserType {
> protected Class klass;
> protected SerA ser=F.g(SerA.class);
> public Class returnedClass() {
> return klass;
> }
> public int[] sqlTypes() {
> return new int[] {Types.BLOB};
> }
> public boolean equals(Object x, Object y) throws HibernateException {
> return ObjectUtils.equals(x, y);
> }
> public Object deepCopy(Object value) {
> klass=value.getClass();
> Copyable copyable=(Copyable)value;
> Object copy=copyable.copy();
> return copy;
> }
> public Object nullSafeGet(ResultSet resultSet,String[] names,SessionImplementor session,Object owner)
> throws HibernateException,SQLException {
> byte[] b=(byte[])BlobType.INSTANCE.nullSafeGet(resultSet,names,session,owner);
> return ser.deser(b,klass);
> }
> public void nullSafeSet(PreparedStatement preparedStatement,Object value,int index,SessionImplementor session)
> throws HibernateException,SQLException {
> BlobType.INSTANCE.nullSafeSet(preparedStatement,ser.ser(value),index,session);
> }
> }
> However, this is not possible because it is not possible to access the object's class in the nullSafeGet method. I propse that the object's class is passed to the nullSafeGet in the UserType interface.
> Regardless of whether is correct in functionality (I haven't tested), I think it would be highly beneficial to know the runtime class of the object in the nullSafeGet metod.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list