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

  • LOBHandler

    I'm using BLOB with db2.
    I'm trying to insert a row into the table and setting the binary stream using lobhandler. But in the AbstractLobCreatingPreparedStatementCallback it is throwing a null pointer exception on LobHandler.
    Here is the code snippet and the stacktrace...
    /*
    private void insertBlob(Object anObject, final MultipleFileFormBean bean, final InputStream is, final int blobLength) {
    assignPrimaryKey(anObject);
    StringBuffer sb = new StringBuffer();
    sb.append(" INSERT INTO ATTACHMENTS(OBJECTID, CASE_ACTIVITY_ID, " );
    sb.append(" CASE_ID, FILE_NAME, FILE_TYPE_CHR, SAT_CREATE_TS , SAT_UPDATE_TS ,SAT_AGENT_ID");
    sb.append(" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" );

    getJdbcTemplate().execute(sb.toString() , new AbstractLobCreatingPreparedStatementCallback(this. lobHandler){
    protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
    ps.setBigDecimal(1, bean.getObjectIdentifier());
    ps.setBigDecimal(2, bean.getCaseActivityId().asBigDecimal());
    ps.setBigDecimal(3, bean.getCaseId().asBigDecimal());
    lobCreator.setBlobAsBinaryStream(ps, 4, is, blobLength);
    ps.setString(5, bean.getFileType().asSqlString());
    ps.setString(6, bean.getCreateSqlTimestamp());
    ps.setString(7, bean.getSqlTimestamp());
    ps.setString(8, bean.getSystemInfo().getSqlUserId());

    System.out.println(ps.toString());

    }
    });
    }

    */

    stack trace..

    Caused by: java.lang.NullPointerException
    at org.springframework.jdbc.core.support.AbstractLobC reatingPreparedStatementCallback.doInPreparedState ment(AbstractLobCreatingPreparedStatementCallback. java)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:536)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:564)


    can somebody help me please TIA

  • #2
    Apparently you don't set a LobHandler in the appropriate class...

    And please use [ code][/code ] tags when posting code, that way your code remains readable (especially when you use indentation).

    Comment


    • #3
      LobHandler

      Hi martein..
      I'm setting the LOBHandler in my DAOImpl class.
      Code snippet..

      public Object insert(Object anObject) {
      MultipleFileFormBean bean = (MultipleFileFormBean) anObject;
      for(Iterator it = bean.getFiles().iterator();it.hasNext() {

      //MultipartFile filename = (MultipartFile) it.next();
      CommonsMultipartFile filename = (CommonsMultipartFile) it.next();
      System.out.println(filename.getName().toString());
      //File inputFile = new File(filename.getOriginalFilename());
      InputStream inputStream = null;
      try{
      inputStream = filename.getInputStream();
      //inputStream = new FileInputStream(inputFile);
      } catch (FileNotFoundException fnfe){
      fnfe.printStackTrace();
      } catch (Exception ex) {
      ex.printStackTrace();

      }
      insertBlob(anObject, bean, inputStream, (int) filename.getSize());
      }
      return bean;
      }

      private void insertBlob(Object anObject, final MultipleFileFormBean bean, final InputStream is, final int blobLength) {
      assignPrimaryKey(anObject);
      StringBuffer sb = new StringBuffer();
      sb.append(" INSERT INTO OIG.DM_ATTACHMENTS(OBJECTID, CASE_ACTIVITY_ID, " );
      sb.append(" CASE_ID, FILE_NAME, FILE_TYPE_CHR, SAT_CREATE_TS , SAT_UPDATE_TS ,SAT_AGENT_ID");
      sb.append(" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" );


      /*sb.append(bean.getObjectIdentifier() + ", ");
      sb.append(bean.getCaseActivityId().asString() + ",");
      sb.append(bean.getCaseId().asString() + ",");
      sb.append(bean.getFileType().asSqlString() + ",");
      sb.append(bean.getCreateSqlTimestamp() + ",");
      sb.append(bean.getSqlTimestamp() + ",");
      sb.append(bean.getSystemInfo().getSqlUserId() + ")"); */
      System.out.println(sb.toString());
      getJdbcTemplate().execute(sb.toString() , new AbstractLobCreatingPreparedStatementCallback(lobHa ndler){
      protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
      ps.setBigDecimal(1, bean.getObjectIdentifier());
      ps.setBigDecimal(2, bean.getCaseActivityId().asBigDecimal());
      ps.setBigDecimal(3, bean.getCaseId().asBigDecimal());
      lobCreator.setBlobAsBinaryStream(ps, 4, is, blobLength);
      ps.setString(5, bean.getFileType().asSqlString());
      ps.setString(6, bean.getCreateSqlTimestamp());
      ps.setString(7, bean.getSqlTimestamp());
      ps.setString(8, bean.getSystemInfo().getSqlUserId());

      System.out.println(ps.toString());

      }
      });
      }

      Comment


      • #4
        Please use [ code][/code ] tags.

        I don't see the setting of the lobHandler anywhere. I see a reference to the lobHandler, but if nothing is there nothing is going to be passesd around.

        Also make sure you don't create a new instance of your DAOImpl but use the one configured in your application context. Can you post the calling code and a partial configuration? (Remember the [ code][/code ] tags).

        Comment


        • #5
          [ code]
          private DefaultLobHandler lobHandler;

          /**
          *
          * Constructors
          *
          **/

          public MultipleFileImpl() {
          }

          /**
          *
          * Accessors
          *
          **/


          public void setLobHandler(DefaultLobHandler lobHandler) {
          this.lobHandler = lobHandler;
          }
          [/code ]


          snippet of the configuration file

          [ code]

          <bean id="lobHandler" class="org.springframework.jdbc.support.lob.Defaul tLobHandler" lazy-init="true">
          <property name="datasource" ref="dataSource"></property>
          </bean>
          [ /code]

          Comment


          • #6
            You configured a lob handler but are you also setting that on-in your DAO... I donīt see that in your configuration....

            And I meant the code tags without the space....

            Comment


            • #7
              LobHandler

              Marten

              What exactly should I do in my configuration.This is my first project on Spring..

              Comment


              • #8
                Well first configure a lobhandler (that is what you have done) next you need to inject that (tell your dao to use it).

                Code:
                <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true">
                  <property name="datasource" ref="dataSource"/>
                </bean>
                Your dao configuration

                Code:
                <bean id="dao" class=""DAOImpl">
                  <property id="lobHandler" ref="lobHandler"/>
                </bean>
                Also your service or whatever calls your dao needs to use the dao configured in the Spring container not a DAO created with 'new DAOImpl()'. The latter call would create a new dao outside the Spring container.

                Comment


                • #9
                  Marten..
                  I have my configuration like this..
                  Code:
                  <bean id="multilplefiledb2" class="us.il.state.hfs.oig.docmgt.dao.MultipleFileImpl">
                  		<property name="lobHandler" ref="lobHandler" />	
                  	</bean>
                  	
                  	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>	
                  	
                  	<bean id="multiplefileupload" class="docmgt.domain.MultipleFileFormBean">		
                  	</bean> 
                  		
                  	<bean name="/upload.view" class="docmgt.asu.controller.MultipleFileUploadController">
                  		<property name="fileUpload" ref="multiplefileupload"/>
                  		<property name="successView" value="upload"/>
                  	</bean> 
                  	
                  	<bean name="/saveupload.view" class="docmgt.asu.controller.SaveMultipleFileUploadController">
                  		<property name="commandClass" value="docmgt.domain.MultipleFileFormBean"/>
                  		<property name="successView" value="redirect:/upload.view"/>
                  		<property name="multiplefiledao" ref="multilplefiledb2" />
                  	</bean> 	
                  	
                  	
                  	<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true">
                  		<property name="datasource" ref="dataSource"></property>
                  	</bean>
                  When I'm running the app I'm getting this error..
                  Code:
                  [12/3/07 10:25:23:281 CST] 00000020 DefaultListab I org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2c242c24: defining beans [homeController,urlMapping,viewResolver,jspViewResolver,/home.view,/save.view,/homepdf.view,asudetails,asudb2,bookmarks,templatedb2,multilplefiledb2,dataSource,txManager,txAdvice,transactionAdvisor,jdbcTemplate,multipartResolver,multiplefileupload,/upload.view,/saveupload.view,lobHandler]; root of factory hierarchy
                  [12/3/07 10:25:23:296 CST] 00000020 DisposableBea E org.springframework.beans.factory.support.DisposableBeanAdapter invokeCustomDestroyMethod Couldn't find a destroy method named 'close' on bean with name 'dataSource'
                  [12/3/07 10:25:23:312 CST] 00000020 DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
                                                   org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/saveupload.view' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Cannot resolve reference to bean 'multilplefiledb2' while setting bean property 'multiplefiledao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multilplefiledb2' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Cannot resolve reference to bean 'lobHandler' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandler' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.jdbc.support.lob.DefaultLobHandler]: Bean property 'datasource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
                  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multilplefiledb2' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Cannot resolve reference to bean 'lobHandler' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandler' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.jdbc.support.lob.DefaultLobHandler]: Bean property 'datasource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
                  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandler' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.jdbc.support.lob.DefaultLobHandler]: Bean property 'datasource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
                  Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.jdbc.support.lob.DefaultLobHandler]: Bean property 'datasource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
                  	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793)
                  	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:645)
                  	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
                  	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:835)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject
                  thanks much

                  Comment

                  Working...
                  X