Hi Guys
I have a problem and it seems to be at least a weird bug.
I have a REST service method which is returning a POJO.
A simplified version:
class WEBAPIResult<E> implements Serializable {
private E result;
private boolean success;
public void setSuccess(boolean success){
this.success = success;
}
public void setResult(E result){
this.result = result;
}
}
The webservice method is the following:
WEBAPIResult<User> getCurrentUserData{
User userResult;
WEBAPIResult<User> webResult = new WEBAPIResult<>();
..............
// the trasanction frame and other codefragments is omitted.
// em is EntityManager
userResult = em.find(User.class, userID, "webView");
webResult.setResult(userResult);
........
return webResult;
}
So that code is failing and the log says that there is null session and LAZY attributes in Pojo which cannot fetched. And I need to fetch them.
The problem is that the em.Find is already fetch all attributes which are in view. Even when I simply return the Entity and not the POJO it will be returned just fine.
The wierd stuff is the following:
IF i do before the return:
Gson.toJSon(userResult); // the result is discarded!
THEN the error is gone, but i’ll get a a full entity returned with all the fields not respecting any security and view configuration.
How can I avoid this bug?
BTW I using 6.5.3
Best Regards!