I'm trying to export data from a database with spring-batch and hibernate. Actually the strong requirement is that the query is a stored procedure returning a cursor. This query and resulting columns can change from time to time.
HTML Code:
<sql-query name="reportingQuery" callable="true">
    { call GET_REPORTING_QUERY(?) }
</sql-query>
So I wrote a simple job with an HibernateCursorItemReader and a FlatFileItemWriter with a DelimitedLineAggregator :
HTML Code:
<batch:step id="extractionStep">
    <batch:tasklet>
        <batch:chunk skip-policy="defaultSkipPolicy" commit-interval="1000">
            <batch:reader>
                <bean class="org.springframework.batch.item.database.HibernateCursorItemReader">
                    <property name="queryName" value="reportingQuery" />
                    <property name="sessionFactory" ref="sessionFactory" />
                    <property name="useStatelessSession" value="true" />
                </bean>
            </batch:reader>
            <batch:writer>
                <bean id="globalQueryItermWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
                    <property name="resource" value="output.csv" />
                    <property name="lineAggregator">
                        <bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                            <property name="delimiter" value="," />
                        </bean>
                    </property>
                </bean>
            </batch:writer>
        </batch:chunk>
    </batch:tasklet>
</batch:step>
my issue, is that this way there is no header line in the output.csv file. I've tried to set fieldExtractor of the line aggregator to a BeanWrapperFieldExrtactor, but I got to set the names. Setting the names doesn't help much more, because hibernate cursor reader only returns an object[] and not a fieldset and then I have an invalid property error.
HTML Code:
<property name="fieldExtractor">
  <bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
    <property name="names" value="ID,NAME,DATE,..."></property>
  </bean>
</property>
So I have basicly two questions :

  1. Is there a way to retrieve the columns names from the hibernate reader and inject it as header of the output file?
  2. How to force hibernate query to return a fieldset (with unknown columns)?


thanks for your help.