In service method, I have to call view when hit rest api using service method invocation(GET)
What do you mean by view? If a UI screen, it’s impossible.
If you explain your situation in more details, we will try to propose a solution.
For Example, I have created Service implementation like this
public List<Employee> getEmployees() {
List<Employee> employees= null;
try (Transaction tx = persistence.createTransaction()) {
EntityManager entityManager = persistence.getEntityManager();
TypedQuery<Employee> employeeTypedQuery = entityManager.createNativeQuery("SELECT * FROM cpreading_employee",Employee.class);
employees = employeeTypedQuery .getResultList();
tx.commit();
}
return employees;
}
Then I hit rest api like http://172.18.1.171:8080/cpreading/rest/v2/services/cpreading_RestService/getEmployees mapping entity is not return in JSON
Why do you use native SQL and not JPQL in the query text?
Because , I need to return deleteTs and deletedBy value in JSON
Just use entityManager.setSoftDeletion(false)
and your JPQL queries will return all entities including soft deleted.
Thanks , If I use JPQL Query Its working fine. But mapped entity value is not return in JSON.
For example I have two entity Employee and Project
In Project entity employee attribute is mapped with Employee Table.
So, If I hit Project Entity using JPQL query employee attribute is not return in JSON
Give any sample example for that