[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7234) No way to get Object's type in nullSafeGet

Vagif Kuliyev (JIRA) noreply at atlassian.com
Tue Apr 10 01:04:48 EDT 2012


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: Bug
          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