BlobUserType类型的nullSafeSet(PreparedStatement,Object,int,SessionImplementor)方法必须覆盖或实现超类型方法

时间:2012-07-18 10:03:04

标签: eclipse hibernate

我正在尝试运行导入的开源但运行后出现此错误:

The method nullSafeSet(PreparedStatement, Object, int, SessionImplementor) of type        
BlobUserType must override or implement a supertype method

这里的方法我没有把任何东西放在上面,因为我真的不需要它,但我必须得到它。

      @Override
protected void nullSafeSet(PreparedStatement ps, Object value , int index ,      
    SessionImplementor si) throws SQLException{}

这是类代码:

   package org.squashtest.csp.tm.internal.infrastructure.hibernate;

   import java.io.IOException;
   import java.io.InputStream;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Types;

   import org.hibernate.HibernateException;
   import org.springframework.jdbc.support.lob.LobCreator;
   import org.springframework.jdbc.support.lob.LobHandler;
   import org.springframework.orm.hibernate3.support.AbstractLobType;
   import org.hibernate.engine.SessionImplementor;
   public class BlobUserType extends AbstractLobType {

@Override
public int[] sqlTypes() {
    return new int[] {Types.BLOB};
}

@Override
public Class<?> returnedClass() {
    return InputStream.class;
}

@Override
protected Object nullSafeGetInternal(ResultSet rs, String[] names,
        Object owner, LobHandler lobHandler) throws SQLException,
        IOException, HibernateException {
       return lobHandler.getBlobAsBinaryStream(rs, names[0]);

}

@Override
protected void nullSafeSetInternal(PreparedStatement ps, int index, Object   
    value, LobCreator lobCreator) throws SQLException,
        IOException, HibernateException {


      if (value != null) {
          lobCreator.setBlobAsBinaryStream(ps, index, (InputStream) value, 
         -1);


     }
      else {
            lobCreator.setBlobAsBytes(ps, index, null);
      }


}




   }

1 个答案:

答案 0 :(得分:3)

此方法是针对不同版本的Hibernate编写的,而不是您使用的方法。如您所见,Hibernate 3.5中的UserType确实有以下内容:

void nullSafeSet(PreparedStatement st,
                 Object value,
                 int index) throws HibernateException, SQLException
另一方面,

Hibernate 4.1确实有一个UserType类,其中方法签名与您的方法匹配:

void nullSafeSet(PreparedStatement st,
                 Object value,
                 int index,
                 SessionImplementor session)
                 throws HibernateException, SQLException