Skip to main content
1 of 3
Sabir Khan
  • 10.2k
  • 7
  • 51
  • 105

but if the column name is different from the field in pojo it is not getting mapped

Obviously, that wouldn't work since your code is written for that very purpose when both names match so I don't understand the surprise element.

Only way out that I can think of is a secondary global map of field names to DB Column name and you refer to it once columnNames.containsKey(fieldName) is false. That map is a manual work and that manual work will always be there since only you as a developer know that which column maps to which field in the POJO. That can't be automated if both are different & external mapping needs to be fed to Java progarm.

That mapping can be kept in an external property file.

There are APIs like apache-commons-dbutils but again manual mapping wouldn't go away as you will have to provide that in your custom - org.apache.commons.dbutils.BeanProcessor

Sabir Khan
  • 10.2k
  • 7
  • 51
  • 105