2012-07-18 83 views
3

我试图运行导入的开放源代码,但运行后,我得到这个错误:型BlobUserType的方法nullSafeSet(PreparedStatement中的对象,INT,SessionImplementor)必须覆盖或实现超方法

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

这里的方法我diidn't放任何东西,因为我并不真的需要它,但我不得不平息它。

 @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); 
     } 


} 




    } 

回答

3

这种方法是写针对不同版本的Hibernate的比你使用的是什么。正如你看到的,用户类型在Hibernate 3.5例如倒是有以下几点:

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 
+0

谢谢你,但我试着添加覆盖:void nullSafeSet(PreparedStatement st, Object value, int index)抛出HibernateException,SQLException但它没有工作我将代码添加到我的文章,你可以检查它,如果你想。非常感谢兄弟 – 2012-07-18 10:37:38

+0

发生了什么? org.springframework.orm.hibernate3.support.AbstractLobType实现org.hibernate.usertype.UserType。因此,Hibernate和Spring版本必须兼容,此外org.squashtest.csp.tm.internal.infrastructure.hibernate.BlobUserType应该与这两者设置的契约一致,因为它扩展了AbstractLobType。 – 2012-07-18 10:46:53

+0

我添加了一个新的jar \t \t \t \t \t org.hibernate作为 \t \t \t 休眠搜索 \t \t \t 4.2.0.Beta1 \t \t 我认为这是源问题我会将版本转换为3.XX – 2012-07-18 11:04:04

相关问题