I need help with what I think is a simple problem....
I have entities that can exist in three different states: NEW, OPEN and PROCESSED. I have named queries setup to retrieve this entities and place them in the appropriate List depending on their state.
Now similar to an email program, when a user clicks on a item that is in the new state, my application will go and update the entity in the database to OPENED. This is all working fine.
Right now, after a user has opened an entity I query the database to get an updates list of each state. As you can probably tell, I want to avoid this. What I would like to do is continue to update the status in database of the opened entity during the request, but I want to avoid hitting the database to rebuild the list. So for example, I want to remove the opened entity from the NEW list and add it to the OPENED list. How can I do this within Hibernate, it looks like hibernate wraps my entity with some sort of CGILIB proxy, so object equality check is always failing when i attempt a list.contains() or list.remove().
Here is some code to clarify
Code:
public String sendOpenActionRequest(CAMApiFacade facadeBean) {
LOG.info("Ajax Request received, about to open a corporate action");
CorporateActionVO action = null;
try {
action = actionManager.markActionStatus(
new CorporateActionIdentifier(corporateActionID),
new CAMStatusVO(CAMStatusVO.STATUS_OPEN));
CorporateActionList newList = facadeBean.getDashboard().getNewActions();
CorporateActionList openList = facadeBean.getDashboard().getOpenActions();
if(newList!=null && newList.contains(action)){
//remove from the new list
newList.remove(action);
//add it to the opened list
openList.add(action);
}
} catch (CAMCheckedException e) {
LOG.error("Unable to close an action. Action ID: "
+ this.corporateActionID);
e.printStackTrace();
action = new CorporateActionVO();
action.setStatusMessage(new StatusMessageVO(
"Save or update failed. We could not mark as processed.",
new java.util.Date()));
}
LOG
.info("Ajax Request completed, successfully opened a corporate action");
//refreshComponents(facadeBean); this is where I would go to the database to refresh the list, but i don't want to have to do that anymore
return action.getStatusMessage().getMessage();
}