My code:
empDet emp = repository.findByActiveFlag("Y");
Here empDet is a entity with 3 columns:
Table with 10 rows so i will use foreach
emp.forEach(e-> {
---mycode---
---and here i got values--
});
Now my question is how to get Column name from Jpa or foreach loop
If you have object of Entity class (empDet) in JPA then from that object you can get the all properties of that class.
As you know in JPA class represent table in database and properties represent columns of that table.
if you have an object of empDet e.i emp
empDet emp=repository.findByActiveFlag("Y");
Field[] members = emp.getClass().getDeclaredFields();
for(Field member:members){
System.out.println(member.getName());
}