Announcement Announcement Module
Collapse
No announcement yet.
JobExecutionContext - Exception when try to store large objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JobExecutionContext - Exception when try to store large objects

    Hi,

    just a short question about the JobExecutionContext ...


    I call
    Code:
    stepExecution.getJobExecution().getExecutionContext().put(String key, Object value);
    in an @AfterStep-Method of an ItemWriter.
    Everything works fine and as supposed as long as the Object I put in the Context doesn't overstep a certain size.
    When the "size limit" is reached SpringBatch throws the following Exception:

    Code:
    org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:141)
        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
        at java.lang.Thread.run(Thread.java:619)
    Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=RedemptionImport at state=RedemptionImport.rdia_transformer with exception
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152)
        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
        ... 3 more
    Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [org.apache.commons.dbcp.PoolableConnection]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: org.apache.commons.dbcp.PoolableConnection cannot be cast to oracle.jdbc.OracleConnection
        at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.createLob(OracleLobHandler.java:511)
        at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.setClobAsString(OracleLobHandler.java:419)
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$1.setValues(JdbcExecutionContextDao.java:197)
        at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:790)
        at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:1)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
        at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:786)
        at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842)
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.persistSerializedContext(JdbcExecutionContextDao.java:193)
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.updateExecutionContext(JdbcExecutionContextDao.java:124)
        at org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext(SimpleJobRepository.java:188)
        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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy0.updateExecutionContext(Unknown Source)
        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:145)
        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
        ... 5 more
    Caused by: java.lang.ClassCastException: org.apache.commons.dbcp.PoolableConnection cannot be cast to oracle.jdbc.OracleConnection
        at oracle.sql.CLOB.createTemporary(CLOB.java:868)
        at oracle.sql.CLOB.createTemporary(CLOB.java:828)
        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.prepareLob(OracleLobHandler.java:547)
        at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.createLob(OracleLobHandler.java:494)
        ... 30 more

    So my question is: What is SpringBatch doing when I put Objects into the ExecutionContext?
    A look on the DB-table "BATCH_JOB_EXECUTION_CONTEXT" and the column "SHORT_CONTEXT" shows all the attributes (and their values) of the objects stored in the context.
    The column's size is a 2500Byte long VARCHAR, what seems to be the max size for my Objects to ...

    Is SpringBatch calling any .toString()-Method or something similar?

    And finally: How to put Objects of any size in the Context?

    Thanks in advance ...

  • #2
    OK, the reason seems to be the NativeJdbcExtractor, when i try to store a CLOB ...

    Code:
    org.springframework.dao.InvalidDataAccessApiUsageException: OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [org.apache.commons.dbcp.PoolableConnection]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: org.apache.commons.dbcp.PoolableConnection cannot be cast to oracle.jdbc.OracleConnection
    The JobRepository has a property called lobHandler-ref referencing to a bean like this one, i think:

    Code:
    <bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
     		<property name="nativeJdbcExtractor">
     			<bean class="THE_JDBCEXTRACTOR_I_NEED"/>
     		</property>
     	</bean>
    But I have absolutely no clue what kind of JdbcExtractor to choose! Any suggestions?

    BTW: I use Oracle 11g ...

    ----------------------------
    //edit:

    after "googling around" a few more minutes I've found what I was looking for:

    <bean class="org.springframework.jdbc.support.nativejdbc .SimpleNativeJdbcExtractor" />
    instead of
    <bean class="THE_JDBCEXTRACTOR_I_NEED"/>
    and everything works fine again ...
    Last edited by b0Ni; Oct 12th, 2010, 10:43 AM. Reason: found the solution by myself

    Comment

    Working...
    X