0

My code:

empDet emp = repository.findByActiveFlag("Y"); 

Here empDet is a entity with 3 columns:

  1. empid
  2. empName
  3. ActiveFlag

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

1
  • 2
    Can you clarify what you mean by "columns"? JPA is an Object Relational Mapping framework. So what you get is a list of Objects of your Entity Type. JPA already maps the columns to your entities properties. What do you want to achieve? Commented Jun 26, 2020 at 11:20

1 Answer 1

1

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()); } 
Sign up to request clarification or add additional context in comments.

1 Comment

Now How to get Value of that field Field[] members = emp.getClass().getDeclaredFields(); for(Field member:members){ if(member.getName().contentEquals("empName")==true) { ----here i want to display value of that field }}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.