My code is working fine except for one problem. The response I am not getting as expected. I have a stored procedure that will return a list of users. Here is code
@NamedNativeQueries({
@NamedNativeQuery(
name="userslist".
query="call list_users",
resultclass=Users.class)})
@Entity
public class Users implements Serializable{
// these are mapped with @Column annotation with table column name
fistname;
lastname;
age;
// getter-setter
//toString
}
Calling Method
StoredProcedureQuery q = entityManager.createStoredProcedureQuery("userslist");
q.execute();
List<Users> userlist = q.getResultList();
Return Response
return new ResponseEntiry<List<Users>>(userlist,OK_status);
Now in post man I getting the response like:
[
[
"David",
"Brrokes",
21
]
]
But I want the output like this:-
[
[
"firstname":"David",
"lastname":"Brrokes",
"age":21
]
]
can you please let me know what I need to change to get the output like this ?
UPDATE After changing the below I am getting the output ex desired but with duplicate entries. Can anyone has any idea why it's coming duplicate ?
StoredProcedureQuery q = entityManager.createStoredProcedureQuery("userslist",Users.class);
Now Response is with Duplicate values:
[
[
"Firstname":"David",
"Lastname":"Brrokes",
"Age":21
"firstname":"David",
"lastname":"Brrokes",
"age":21
]
]
CodePudding user response:
Finally resolved this issue. Not sure the exact reason but after removing the getter-setter method from Entity class I got the expected output