-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Removing a hibernate object from a collection
PostPosted: Tue Jul 24, 2007 9:27 am 
Newbie

Joined: Mon Jul 23, 2007 11:58 am
Posts: 15
Location: New Jersey
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();
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 3:28 pm 
Newbie

Joined: Mon Jul 23, 2007 11:58 am
Posts: 15
Location: New Jersey
Overidding the Object.equals() method was my solution for this...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.