Search code examples
springfile-uploadoracle11gweblogic11g

Connection closed when saving blob


I'm having a problem when uploading files on a weblogic application.

Once the fileuploader has finished saving the file, the following exception appears:

java.sql.SQLException: Conexión cerrada
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:445)
at oracle.sql.BLOB.getDBAccess(BLOB.java:882)
at oracle.sql.BLOB.freeTemporary(BLOB.java:584)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.close(OracleLobHandler.java:412)
at org.springframework.jdbc.support.lob.SpringLobCreatorSynchronization.afterCompletion(SpringLobCreatorSynchronization.java:76)
at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:133)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:951)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:926)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:319)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy74.guardarFichero(Unknown Source)

At other environments this problem doesn't appear, so I think it must be some configuration on the JDBC driver but I'm not sure wich one I have to modify.

The invoking struts

    private void adjuntarFichero()throws Exception {
    logger.debug("uploadFileName = "+uploadFileName);       
    if (uploadFileName!=null && !uploadFileName.equals("")) {
        HttpSession session = request.getSession();
        HashMap<Long,String> ficheros = (HashMap<Long,String>)session.getAttribute("ficheros");
        if (ficheros == null) ficheros = new HashMap<Long,String>();

        Fichero file = new FicheroImpl();
        file.setNombre(uploadFileName);
        file.setFichero(getBytesFromFile(upload));
        file = gestorFichero.guardarFichero(file);

        ficheros.put(file.getId(), uploadFileName);
        session.setAttribute("ficheros", ficheros);
    }        
}  

the error is produced inside the "guardarFichero" method, who invokes a DAO class that takes care of the saving

public abstract class gestorFichero extends org.springframework.orm.hibernate3.support.HibernateDaoSupport{

public Fichero guardarFichero (Fichero fichero){
    Debug.prec(fichero, "El fichero no puede ser nulo");
    return (Fichero)create(TRANSFORM_NONE, fichero);
}   
public java.lang.Object create(final int transform, final    com.aena.sgc.Fichero fichero)
{
    if (fichero == null){
        throw new IllegalArgumentException("Fichero.create - 'fichero' can not be null");
    }
    this.getHibernateTemplate().save(fichero);
    return this.transformEntity(transform, fichero);
}

Solution

  • Finally I discovered wich was the problem.

    It was related to the driver class. Originally we had the datasource configured to use the XA driver oracle.jdbc.xa.client.OracleXADataSource and whenever we finished uploading a file, the exception was thrown.

    Once I changed the driver to oracle.jdbc.OracleDriver these errors dissapeared.