Andrea Girardi
Andrea Girardi

Reputation: 4437

Query returns multiple records

I've a problem with a query that returns multiple value using Spring 3.

I'm using this to retrieve values, but the TemplateFlow objects returned from DB are always null (all field contains null or default value).

List<TemplateFlow> flows = (List<TemplateFlow>) getJdbcTemplate().query(
   sqlString, 
   ParameterizedBeanPropertyRowMapper.newInstance(TemplateFlow.class)
);

TemplateFlow is a class that contains all field. I'm retrieving some values after an update, is it possible I need to commit the changes? (but I'm not using any kind of transaction).

public class TemplateFlow {

    private int id_templateflow;
    private int id_templateprocess;

    public int id_templateflow() { return this.id_templateflow; }
    public void id_templateflow(int id_templateflow) { this.id_templateflow = id_templateflow; }    

    public int id_templateprocess() { return this.id_templateprocess; }
    public void id_templateprocess(int id_templateprocess) { this.id_templateprocess = id_templateprocess; }

}

I I try to run the query directly on DB it returns two rows.

thanks for help! Andrea

Upvotes: 0

Views: 610

Answers (1)

skaffman
skaffman

Reputation: 403591

Your TemplateFlow class does not conform to the javabean pattern, and ParameterizedBeanPropertyRowMapper requires this to be the case:

Column values are mapped based on matching the column name as obtained from result set metadata to public setters for the corresponding properties.

For example, you should have

int getId_templateflow()
void setId_templateflow(int)

instead of

int id_templateflow()
void id_templateflow(int)

However, I'd advise against using ParameterizedBeanPropertyRowMapper at all - it couples your database too tightly to your code, and that's not a good thing. Consider instead writing your own implementation of RowMapper.

Upvotes: 2

Related Questions