java - Spring batch 2.2.0 and Hibernate 3 compatibility -


i using version 2.2.0 of spring batch , version 3.6.4 of hibernate. in java-based spring configuration want configure bean of class hibernateitemwriter this:

@bean public <e> itemwriter<e> hibernateitemwriter(hibernateoperations hibernatetemplate) {     hibernateitemwriter<e> writer = new hibernateitemwriter<e>();     writer.sethibernatetemplate(hibernatetemplate);     return writer; } 

but in version of spring batch, method sethibernatetemplate of class hibernateitemwriter deprecated.

/**  * public setter {@link hibernateoperations} property.  *  * @param hibernatetemplate  *            hibernatetemplate set  * @deprecated of 2.2 in favor of using hibernate's session management apis directly  */ public void sethibernatetemplate(hibernateoperations hibernatetemplate) {     this.hibernatetemplate = hibernatetemplate; }  

i tried configure hibernateitemwriter followed:

@bean public <e> itemwriter<e> hibernateitemwriter(sessionfactory sessionfactory) {     hibernateitemwriter<e> writer = new hibernateitemwriter<e>();     writer.setsessionfactory(sessionfactory);     return writer; } 

and got exception on spring batch job execution:

java.lang.nosuchmethoderror: org.hibernate.sessionfactory.getcurrentsession()lorg/hibernate/session; @ org.springframework.batch.item.database.hibernateitemwriter.dowrite(hibernateitemwriter.java:135) @ org.springframework.batch.item.database.hibernateitemwriter.write(hibernateitemwriter.java:113) @ org.springframework.batch.core.step.item.simplechunkprocessor.writeitems(simplechunkprocessor.java:175) @ org.springframework.batch.core.step.item.simplechunkprocessor.dowrite(simplechunkprocessor.java:151) @ org.springframework.batch.core.step.item.simplechunkprocessor.write(simplechunkprocessor.java:274) @ org.springframework.batch.core.step.item.simplechunkprocessor.process(simplechunkprocessor.java:199) @ org.springframework.batch.core.step.item.chunkorientedtasklet.execute(chunkorientedtasklet.java:75) @ org.springframework.batch.core.step.tasklet.taskletstep$chunktransactioncallback.dointransaction(taskletstep.java:395) @ org.springframework.transaction.support.transactiontemplate.execute(transactiontemplate.java:130) @ org.springframework.batch.core.step.tasklet.taskletstep$2.doinchunkcontext(taskletstep.java:267) @ org.springframework.batch.core.scope.context.stepcontextrepeatcallback.doiniteration(stepcontextrepeatcallback.java:77) @ org.springframework.batch.repeat.support.repeattemplate.getnextresult(repeattemplate.java:368) @ org.springframework.batch.repeat.support.repeattemplate.executeinternal(repeattemplate.java:215) @ org.springframework.batch.repeat.support.repeattemplate.iterate(repeattemplate.java:144) @ org.springframework.batch.core.step.tasklet.taskletstep.doexecute(taskletstep.java:253) @ org.springframework.batch.core.step.abstractstep.execute(abstractstep.java:195) @ org.springframework.batch.core.job.simplestephandler.handlestep(simplestephandler.java:137) @ org.springframework.batch.core.job.flow.jobflowexecutor.executestep(jobflowexecutor.java:64) @ org.springframework.batch.core.job.flow.support.state.stepstate.handle(stepstate.java:60) @ org.springframework.batch.core.job.flow.support.simpleflow.resume(simpleflow.java:152) @ org.springframework.batch.core.job.flow.support.simpleflow.start(simpleflow.java:131) @ org.springframework.batch.core.job.flow.flowjob.doexecute(flowjob.java:135) @ org.springframework.batch.core.job.abstractjob.execute(abstractjob.java:301) @ org.springframework.batch.core.launch.support.simplejoblauncher$1.run(simplejoblauncher.java:134) @ org.springframework.core.task.synctaskexecutor.execute(synctaskexecutor.java:48) @ org.springframework.batch.core.launch.support.simplejoblauncher.run(simplejoblauncher.java:127) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:616) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:319) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150) @ org.springframework.batch.core.configuration.annotation.simplebatchconfiguration$passthruadvice.invoke(simplebatchconfiguration.java:117) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:202) @ sun.proxy.$proxy20.run(unknown source) @ org.springframework.batch.test.joblaunchertestutils.launchjob(joblaunchertestutils.java:152) @ ... 

do have solution that?

it seems spring batch 2.2.0 not support hibernate 3

thank you

in release notes, of spring batch 2.2.0; seems support (by default) hibernate 4. see: batch-1904 upgrade support of hibernate hibernate 4

the reported error happen @ runtime, when using hibernate 3 (tested 3.6.2.release) when referencing org.springframework.batch.item.database.hibernateitemwriter

to solve problem, use custom implementation hibernateitemwriter. example see source on class in spring 2.1.9 (see hibernateitemwriter); compatible hibernate 3


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -