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

  • Multiple ItemWrite Issue

    Hi I am trying to read some data from database and trying to create an xml file using Castor.
    It write two files and then throws this error...

    2009-12-16 08:20:16,439 DEBUG [org.springframework.batch.core.step.tasklet.Taskle tStep] - <Applying contribution: [StepContribution: read=1, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]>
    2009-12-16 08:20:16,439 ERROR [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step: class org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSourceInitializer' defined in class path resource [launch-context.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE BATCH_JOB_INSTANCE (
    JOB_INSTANCE_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
    VERSION BIGINT ,
    JOB_NAME VARCHAR(100) NOT NULL,
    JOB_KEY VARCHAR(32) NOT NULL,
    constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
    )]; nested exception is java.sql.SQLException: Table already exists: BATCH_JOB_INSTANCE in statement [CREATE TABLE BATCH_JOB_INSTANCE]>
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSourceInitializer' defined in class path resource [launch-context.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE BATCH_JOB_INSTANCE (
    JOB_INSTANCE_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
    VERSION BIGINT ,
    JOB_NAME VARCHAR(100) NOT NULL,
    JOB_KEY VARCHAR(32) NOT NULL,
    constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
    )]; nested exception is java.sql.SQLException: Table already exists: BATCH_JOB_INSTANCE in statement [CREATE TABLE BATCH_JOB_INSTANCE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)

  • #2
    Writing XML file by reading the database

    I am trying to read the data from the database using JpaPagingItemReader.
    And then write the same data into an xml file.
    though I am able to read the file successfully sand able to convert the obtained data into Objects. I am not yet sure How should I write it to the xml file where all the obtained data is written into the single xml file itself.

    Any idea on this?

    Comment


    • #3
      You have a bean called 'dataSourceInitializer' that is trying to create the batch tables. However, the tables apparently already exist. So you should remove the initializer since it is not needed.

      Comment


      • #4
        Thanks for your response...
        But when I remove the DatasourceInitializers it complains that the table does not exists.

        The above mentioned error I get after 2 rows have already been processed.
        So does it mean every time I run my client, it creates those tables and when it stops it delete them.

        But still I dont understand why it five me the " table already exists" error when it has already processed 2 rows.

        Comment


        • #5
          well some headway I have been able to make...

          If I change the value of commitInterval of my simpleStep from 1 to 10, it is able to write 10 objects into single xml file.
          Also the error that I reported here is gone.

          <bean id="simpleStep" class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean"
          abstract="true">
          <property name="transactionManager" ref="transactionManager" />
          <property name="jobRepository" ref="jobRepository" />
          <property name="startLimit" value="100" />
          <property name="commitInterval" value="10" />
          </bean>

          And also of-course I had to pass the list of Objects to the Castor Marshaller...

          This is write method of my ItemWriter implementation.
          public void write(List<? extends TradeVO> tradeList) throws Exception {
          FileWriter file = new FileWriter("output.xml");
          Marshaller.marshal(tradeList, file);
          file.close();
          }
          Last edited by springprem; Dec 17th, 2009, 02:23 AM.

          Comment

          Working...
          X