HibernateCursorItemReader,与多个实体映射到同一个表的问题,是否可能?

时间:2014-06-12 22:03:59

标签: hibernate spring-batch

我有3个类映射到同一个表。这是现有代码。

<class name="com.blah.PersonRaw" table="Person" entity-name="PersonBasicRaw"   mutable="false">  ....  (contains some mappings)
<class name="com.blah.PersonRaw" table="Person" entity-name="PersonRaw" mutable="false">.....         (Just basic object ,with no mappings)
<class name="com.blah.Person" table="Person" entity-name="Person">......                               (Full mapping)

现在,如果我在阅读器和处理器中使用Person(第3个)而不是personRaw,我的工作运行正常。但如果我使用personRaw我会收到错误。我没有得到关于错误是什么以及为什么抛出错误的信息。

我在处理器中添加了一个前一步,我的工作正在执行到前一步。

这是日志

<!    
Before Step Called:
Hibernate: select persona0_.person as person1_70_ .....from person persona0_
ERROR [main] (AbstractStep.java:225) - Encountered an error executing step stepR2 in    job generateDepositPremiumJob
java.lang.NoSuchMethodError: org.springframework.classify.BinaryExceptionClassifier.classify(Ljava/lang/Throwable;)Ljava/lang/Boolean;
at org.springframework.batch.core.step.item.SimpleRetryExceptionHandler.handleException(SimpleRetryExceptionHandler.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.doHandle(RepeatTemplate.java:294)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:220)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:162)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:141)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at com.reinsurance.urs.batch.functionaltest.BatchJobTest.testExecute(BatchJobTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

这里是我的jobs.xml

<job id="generatePersonDetails"restartable="false"      xmlns="http://www.springframework.org/schema/batch">
    <step id="stepR2">
        <tasklet>
            <chunk reader="generatepersonReader" processor="generatePersonProcessor"
                writer="generatePersonWriter" skip-limit="5" commit-interval="20">
                <skippable-exception-classes>
                    <include class="java.lang.RuntimeException" />
                </skippable-exception-classes>
            </chunk>
        </tasklet>
    </step>
</job>
<bean id="generatePersonReader"
    class="org.springframework.batch.item.database.HibernateCursorItemReader">
    <property name="queryString" value="from PersonRaw"/>
    <property name="sessionFactory" ref="mySessionFactory" />
</bean>

这是我的处理器

@Component("generatePersonProcessor")
public class GeneratePersonProcessor extends StepExecutionListenerSupport implements ItemProcessor<PersonRaw, PersonRaw> {

public void beforeStep(StepExecution stepExecution) {
    System.out.println("Before Step Called:");

    this.stepExecution = stepExecution;
}

@Override
public PersonRaw process(PersonRaw person) throws Exception {

    System.out.println("in Processing");


    return person;
}

}

我无法理解为什么会失败。 我正在使用SpringBatch 3.0和Hibernate 4.x,以及sql server 2012

1 个答案:

答案 0 :(得分:0)

从堆栈跟踪中,您的依赖项中缺少spring-retry库(BinaryExceptionClassifier是重试库的一部分)。
检查你的课程路径。