I had a problem where certain fields in my POJO were not getting populated.
The reason being that DBUtils does not make use of the '@Column' annotation and therefore some extra code is needed.
In our case it occurred for every column that had an underscore in the name but not in the POJO getters & setters.
A snipped from my POJO could look like this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Column(name="WIND_DIRECTION", nullable=true) | |
public String getWindDirection() | |
{ | |
return mWindDirection; | |
} | |
public void setWindDirection(String aWindDirection) | |
{ | |
mWindDirection = aWindDirection; | |
} |
Using the same Dao in the post I refferred to above the ResultSetHandler will now be created as follows:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Map<String, String> columnToPropertyOverrides = new HashMap<>(); | |
columnToPropertyOverrides.put("WIND_DIRECTION", "WindDirection"); | |
BeanProcessor dateForProcessor = new BeanProcessor(columnToPropertyOverrides); | |
BasicRowProcessor rp = new BasicRowProcessor(dateForProcessor); | |
ResultSetHandler<List<T>> resultSetHandler = new BeanListHandler<T>(aType, rp); |
No comments:
Post a Comment