Ad

What Does Failed To Convert Property Value Of Type '$Proxy0 To Required Type Means In This Case?

- 1 answer

i'm facing this error message:

Error creating bean with name 'jdbcWriter', Initialization of bean failed, Failed to convert property value of type '$Proxy0 to required type for property 'itemPreparedStatementSetter'.

This is my code:

<beans:bean id="jdbcWriter" 
  class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    <beans:property name="dataSource" ref="dataSource"/> 
    <beans:property name="sql" value="update Trans_Tst set (amount) values (?) 
           where id= ?"/>
    <beans:property name="itemPreparedStatementSetter" 
           ref="WriterSqlParameterSetter"/> 
</beans:bean> 
<beans:bean id="WriterSqlParameterSetter" 
  class="sa.com.anb.itg.dev.settlement.batch.WriterSqlParameterSetter" scope="step">
    <beans:property name="amount" value="#{jobParameters[amount]}"/>
    <beans:property name="id" value="#{jobParameters[id]}"/>  
</beans:bean>




public class WriterSqlParameterSetter implements 
  ItemPreparedStatementSetter<transactionas>{

public void setValues(transactionas ts, PreparedStatement ps) throws SQLException {
        ps.setDouble(1, ts.GetAmount());
        ps.setInt(2, ts.GetID());               
    }
}

can anyone help me to solve this error? Is this error has anything to do with the value of the properties of the WriterSqlParameterSetter?

Ad

Answer

Ok, first thing i see here:

WriterSqlParameterSetter is a ItemPreparedStatementSetter! fine!

But even if you declare:

 <beans:property name="amount" value="#{jobParameters[amount]}"/>
 <beans:property name="id" value="#{jobParameters[id]}"/>  

I don't see theses properties in :

public class WriterSqlParameterSetter implements 
  ItemPreparedStatementSetter<transactionas>{

public void setValues(transactionas ts, PreparedStatement ps) throws SQLException {
    ps.setDouble(1, ts.GetAmount());
    ps.setInt(2, ts.GetID());               
    }
}

And even if the properties were declared, the ItemPreparedStatementSetter wont use them since, it takes value from the object received in the writer (eg. transactionas).

I am trying to see why you need to pass an amount and an Id in the jobParameters? Can you explain what you are trying to achieve at a higher level.?

Ad
source: stackoverflow.com
Ad