Announcement Announcement Module
Collapse
No announcement yet.
Blob save issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Blob save issue

    Hi all,

    Am trying to save a Blob file into oracle DB, but I keep getting the following exception:

    Code:
    Caused by: org.springframework.jdbc.UncategorizedSQLException: Hibernate flushing: could not insert: [com.billz.csr.pojo.AccountFileAttache]; uncategorized SQLException for SQL [insert into ACCOUNT_FILE_ATTACHE (ACCOUNT_NUMBER, CREATED_BY, CREATED_DATE, FILE_NAME, FILE_SIZE, FILE_TYPE, UPDATED_BY, UPDATED_DATE, VALUE_ATTACHED, FILE_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [null]; error code [17090]; operation not allowed: streams type cannot be used in batching; nested exception is java.sql.SQLException: operation not allowed: streams type cannot be used in batching
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.convertJdbcAccessException(HibernateTransactionManager.java:805)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:791)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:394)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy21.addAccountDetailAttachment(Unknown Source)
    	at com.billz.csr.web.gwt.server.CSRServiceGWTWrapperImpl.addAccountDetailAttachment(CSRServiceGWTWrapperImpl.java:430)
    	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 com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    	... 22 more
    Caused by: java.sql.SQLException: operation not allowed: streams type cannot be used in batching
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    	at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:3775)
    	at org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:172)
    	at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:31)
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
    	... 35 more
    If I try to upgrade the oracle dirver I get the following exception:

    Code:
    Caused by: java.sql.SQLException: No suitable driver
    	at java.sql.DriverManager.getDriver(DriverManager.java:264)
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
    my mapping class looks like this:

    Code:
    public class AccountFileAttache implements java.io.Serializable {
    
    	private static final long serialVersionUID = 1L;
    	private BigDecimal fileId;
    	private String accountNumber;
    	private String fileName;
    	private String fileType;
    	private BigDecimal fileSize;
    	private Blob valueAttached;
    	private Timestamp createdDate;
    	private String createdBy;
    	private Timestamp updatedDate;
    	private String updatedBy;
    
    	// Constructors
    
    	/** default constructor */
    	public AccountFileAttache() {
    	}
    
    	/** minimal constructor */
    	public AccountFileAttache(BigDecimal fileId) {
    		this.fileId = fileId;
    	}
    
    	/** full constructor 
    	 * @throws IOException */
    	public AccountFileAttache(BigDecimal fileId, String accountNumber,
    			String fileName, String fileType, BigDecimal fileSize, Blob valueAttached,
    			Timestamp createdDate, String createdBy, Timestamp updatedDate,
    			String updatedBy) {
    		this.fileId = fileId;
    		this.accountNumber = accountNumber;
    		this.fileName = fileName;
    		this.fileType = fileType;
    		this.fileSize = fileSize;
    		this.valueAttached = valueAttached;
    		this.createdDate = createdDate;
    		this.createdBy = createdBy;
    		this.updatedDate = updatedDate;
    		this.updatedBy = updatedBy;
    	}
    
    	// Property accessors
    	@Id
    	@Column(name = "FILE_ID", unique = true, nullable = false, precision = 20, scale = 0)
    	public BigDecimal getFileId() {
    		return this.fileId;
    	}
    
    	public void setFileId(BigDecimal fileId) {
    		this.fileId = fileId;
    	}
    
    	@Column(name = "ACCOUNT_NUMBER", length = 12)
    	public String getAccountNumber() {
    		return this.accountNumber;
    	}
    
    	public void setAccountNumber(String accountNumber) {
    		this.accountNumber = accountNumber;
    	}
    
    	@Column(name = "FILE_NAME", length = 100)
    	public String getFileName() {
    		return this.fileName;
    	}
    
    	public void setFileName(String fileName) {
    		this.fileName = fileName;
    	}
    
    	@Column(name = "FILE_TYPE", length = 20)
    	public String getFileType() {
    		return this.fileType;
    	}
    
    	public void setFileType(String fileType) {
    		this.fileType = fileType;
    	}
    
    	@Column(name = "VALUE_ATTACHED")
    	public Blob getValueAttached() {
    		return this.valueAttached;
    	}
    
    	public void fillValueAttached(String filePath) throws IOException {
    		InputStream stream=new FileInputStream(filePath);
    		this.valueAttached = Hibernate.createBlob(stream);
    	}
    	
    	public void setValueAttached(Blob valueAttached) {
    		this.valueAttached = valueAttached;
    	}
    
    	@Column(name = "CREATED_DATE", length = 7)
    	public Timestamp getCreatedDate() {
    		return this.createdDate;
    	}
    
    	public void setCreatedDate(Timestamp createdDate) {
    		this.createdDate = createdDate;
    	}
    
    	@Column(name = "CREATED_BY", length = 30)
    	public String getCreatedBy() {
    		return this.createdBy;
    	}
    
    	public void setCreatedBy(String createdBy) {
    		this.createdBy = createdBy;
    	}
    
    	@Column(name = "UPDATED_DATE", length = 7)
    	public Timestamp getUpdatedDate() {
    		return this.updatedDate;
    	}
    
    	public void setUpdatedDate(Timestamp updatedDate) {
    		this.updatedDate = updatedDate;
    	}
    
    	@Column(name = "UPDATED_BY", length = 30)
    	public String getUpdatedBy() {
    		return this.updatedBy;
    	}
    
    	public void setUpdatedBy(String updatedBy) {
    		this.updatedBy = updatedBy;
    	}
    
    	public void setFileSize(BigDecimal fileSize) {
    		this.fileSize = fileSize;
    	}
    	
    	@Column(name = "FILE_SIZE")
    	public BigDecimal getFileSize() {
    		return fileSize;
    	}
    
    }
    in my DAO this is what I do:

    Code:
    public AccountFileAttache save(AccountFileAttache transientInstance) {
    		log.debug("saving AccountFileAttache instance");
    		try {
    			getHibernateTemplate().save(transientInstance);
    			return transientInstance;
    		} catch (Exception re) {
    			log.error("save failed", re);
    			return null;
    		}
    	}

  • #2
    I believe that you need to use the @Lob annotation for saving Blobs/Clobs with JPA/Hibernate.

    Comment


    • #3
      I already tried that but no use!! the same exception is thrown!

      Comment


      • #4
        Solved

        Finally I got it working:

        The first exception :
        Code:
        Caused by: java.sql.SQLException: operation not allowed: streams type cannot be used in batching
        	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
        	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
        	at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:3775)
        	at org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:172)
        	at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:31)
        	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
        	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
        	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
        	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
        	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
        	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
        	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
        	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
        	... 35 more
        This was solved by upgrading to the latest oracle driver (ojdbc6.jar) in my case, which resulted into the second exception:

        Code:
        Caused by: java.sql.SQLException: No suitable driver
        	at java.sql.DriverManager.getDriver(DriverManager.java:264)
        	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
        This was invalid url!!! even though my old url was working fine with ojdbc14.jar

        ojdbc14.jar url
        Code:
        connection:oracle:thin:@localhost:1521:SID
        ojdbc6.jar:
        Code:
        jdbc:oracle:thin:@localhost:1521:SID
        Finally do not forget to use @Lob in the hibernate annotation!

        Comment

        Working...
        X