java - How to map the marshalled object values(reader) to hibernate entity object(writer) in spring batch -
i new spring batch, after extensive search didn't clue on how map xml marshalled object value hibernate entity object. specific, think follows same approach fieldsetmapper not sure how marshallobject instead of flatfieldset. please help.
fyi: should use hibernate , not jdbctemplate or preparedstatementsetter etc.
the batch config file:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <import resource="//context.xml" /> <!-- <context:component-scan base-package="com.politico.batchhandle.marshallbatch" /> --> <!-- parallel job processing --> <job id="feedprocesser" xmlns="http://www.springframework.org/schema/batch"> <!-- <split id="split1"> <flow> --> <step id="stepfeedprocess"> <!-- <tasklet task-executor="taskexecutor" throttle-limit="10"> --> <tasklet> <chunk reader="xmlmultireader" writer="datawriter" processor="dataprocessor" commit-interval="10" /> </tasklet> </step> <!-- </flow> </split> --> </job> <!-- <bean id="testreader" class="com.politico.batchhandle.marshallbatch.datareader" /> --> <bean id="dataprocessor" class="com.politico.batchhandle.marshallbatch.dataprocessor" /> <bean id="datawriter" class="com.politico.batchhandle.marshallbatch.datawriter" /> <!-- <bean id="taskexecutor" class="org.springframework.core.task.simpleasynctaskexecutor" /> --> <bean id="xmlmultireader" class="org.springframework.batch.item.xml.staxeventitemreader"> <property name="fragmentrootelementname" value="crs-bill-summary" /> <property name="resource" value="classpath:xmlfiles\\bill_digest.xml" /> <property name="unmarshaller" ref="reportunmarshaller" /> <property name="fieldsetmapper" ref="datafieldsetmapper" /> </bean> <bean id="reportunmarshaller" class="org.springframework.oxm.jaxb.jaxb2marshaller"> <property name="classestobebound"> <list> <value>com.politico.jaxbconvert.readerto.crsbillsummary</value> </list> </property> <property name="mappinglocation" value="classpath:/usermapping.xml" /> </bean> <bean id="datafieldsetmapper" class="com.politico.batchhandle.dao.datafieldsetmapper"> </bean> </beans>
i assumed xml marshall object can mapped using fieldsetmapper, here corresponding code:
public class datafieldsetmapper implements fieldsetmapper<crsbillsummary>{ @override public crsbillsummary mapfieldset(fieldset fieldset) throws bindexception { // todo auto-generated method stub return null; } }
i sure using wrong interface fieldsetmapping , please me right approach..
please add 1 xml
<bean id="reportunmarshaller" class="org.springframework.oxm.xstream.xstreammarshaller"> <property name="aliases"> <util:map id="aliases"> <entry key="trade" value="xxx.crsbillsummary" /> <entry key="property1" value="java.math.bigdecimal" /> <entry key="property2" value="java.lang.string" /> </util:map> </property> </bean>
note: crsbillsummary in case, hope should use pojo class not entity one. , can convert entity @ writer layer persist database. best practice recommend use avoid mistakes unattended objects persist database.
Comments
Post a Comment