I'm trying to compare two identical objects. When the page first loads, they are equal, however when I refresh the page a second time, the do not equal each other despite the data or object not changing.
What I'm doing.
I have a CurrentUser
obj that I store in the user session at login. I use the currentUser
to compare against the assignedUser
of a form. If the currentUser.equals(pr.getAssignedUser())
then I enable access. AssignedUser
is a hibernate variable reference to CurrentUser
. If I remove getClass() != obj.getClass
from my equals override and just use property comparisons, everything works fine.
The thing that concerns me most is it works on the first access, however it doesn't on a page refresh. Without knowing what is going on, I worry about a memory leak.
Does anybody know what might be going on here?
CurrentUserServiceImpl.class
@Scope(ScopeConstants.PERTHREAD)
public class CurrentUserServiceImpl implements CurrentUserServiceService {
private final CrudDAO crudDAO;
private CurrentUser currentUser;
public CurrentUserServiceImpl(CrudDAO crudDAO) {
this.crudDAO = crudDAO;
}
public Long getUserId() {
return getUser().getId();
}
public CurrentUser getCurrentUser() {
if (this.isUserExist() && applicationUser == null) {
PersonProfile personProfile = (PersonProfile) SecurityUtils.getSubject().getPrincipal();
currentUser = crudDAO.find(personProfile.getUid());
}
return currentUser;
}
public boolean isUserExist() {
return SecurityUtils.getSubject().getPrincipal() != null;
}
}
PurchaseRequisition.class
public PurchaseRequisition {
@Inject
private CurrentUserService currentUserService;
@Inject
private CrudDAO crudDAO;
void setupRender() {
CurrentUser currentUser = currentUserService.getCurrentUser();
PurchaseReq pr = crudDAO.find(PurchaseReq.class, id);
if(currentUser.equals(pr.getAssignedUser()) {
System.out.println("equal");
}
}
}