I am trying to set the the field values in entity class using the annotation column names.
Below is an example
Loans is my entity class
<code>public class Loans{
@Column(name = "CORR_ID")
private String corrId;
@Column(name = "FILE_RCEIVED_MONTH")
private Date fileRcvdMonth;
}
</code>
<code>public class Loans{
@Column(name = "CORR_ID")
private String corrId;
@Column(name = "FILE_RCEIVED_MONTH")
private Date fileRcvdMonth;
}
</code>
public class Loans{
@Column(name = "CORR_ID")
private String corrId;
@Column(name = "FILE_RCEIVED_MONTH")
private Date fileRcvdMonth;
}
I have a Map which have physical column names from table and its respective values , this is coming from external system.
<code>Map<String , String > configColumnNames = new HashMap<>();
configColumnNames.put("CORR_ID","123");
configColumnNames.put("FILE_RCEIVED_MONTH","11");
</code>
<code>Map<String , String > configColumnNames = new HashMap<>();
configColumnNames.put("CORR_ID","123");
configColumnNames.put("FILE_RCEIVED_MONTH","11");
</code>
Map<String , String > configColumnNames = new HashMap<>();
configColumnNames.put("CORR_ID","123");
configColumnNames.put("FILE_RCEIVED_MONTH","11");
What i am trying to do is like below
<code>for (Field field : loan.getClass().getDeclaredFields()) {
Column column = field.getAnnotation(Column.class);
if(configColumnNames.containsKey(column.name())){
//loan.setCorrId(configColumnNames.get(column.name()));
// how i can find which field (setCorrId) in loan to set
}
}
</code>
<code>for (Field field : loan.getClass().getDeclaredFields()) {
Column column = field.getAnnotation(Column.class);
if(configColumnNames.containsKey(column.name())){
//loan.setCorrId(configColumnNames.get(column.name()));
// how i can find which field (setCorrId) in loan to set
}
}
</code>
for (Field field : loan.getClass().getDeclaredFields()) {
Column column = field.getAnnotation(Column.class);
if(configColumnNames.containsKey(column.name())){
//loan.setCorrId(configColumnNames.get(column.name()));
// how i can find which field (setCorrId) in loan to set
}
}
Or is there any other better way to implement this .
1