Skip to content
Advertisement

How to get ID fields from table using spring batch

I´m trying to get all fields from a table using spring batch.

I got all fields, except the ID fields (primary key e foreign key)

Below is my reader:

JavaScript

Below is my writer:

JavaScript

The others fields comes with success, but the ID fields like transactionId and deposit comes null.

I think there is some kind of protection that not permit these fields show its values.

Someone can help me?

Advertisement

Answer

The column name in your table is ID_TRANSACTION, but the getter/setter that you seem to be generating with lombok would be getTransactionId/setTransactionId, which do not match the column name. According to the javadoc of BeanPropertyRowMapper, you can use an alias if the column name does not match the field name. Here is an excerpt from the javadoc:

JavaScript

In your case, you need to update your query to something like:

JavaScript

Here is a quick example:

JavaScript

This prints:

JavaScript

If you change the sql query to select * from person, you will see the that the id field won’t be mapped correctly, because the BeanPropertyRowMapper won’t find a getter/setter named getPerson_Id/setPerson_Id.

Advertisement