-->
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.  [ 1 post ] 
Author Message
 Post subject: Complex object not being saved properly in an EJB system
PostPosted: Tue Dec 09, 2003 6:35 pm 
Newbie

Joined: Wed Aug 27, 2003 1:37 am
Posts: 10
Location: Kyrgyzstan
Here is the scenerio.

1. A standalone client program loads a list of DistributionPlan objects. This is accomplished by calling a SSB which creates a new Hibernate Session object which is used to create a Query which then returns the list of object via the list() method.

2. The client program then presents a DistributionObject to the user for manipulation. When the user is done he/she clicks save which sends the DistributionPlan in question over the network to another SSB which includes the following code.


Code:
//hack to get the shipment to refresh properly
    Map products = new HashMap(plan.getProducts());
    plan.setProducts(products);
    Map regionQuantities = new HashMap(plan.getRegionQuantities());
    plan.setRegionQuantities(regionQuantities);
    Set shipments = new HashSet(plan.getShipments());
    plan.setShipments(shipments);
    Iterator shipmentProcessor = shipments.iterator();
    while(shipmentProcessor.hasNext()) preProcessShipment((Shipment)shipmentProcessor.next());
    database.save(plan);
    return plan;


This is the relavant portion of the database.save() call listed above.

Code:
try
    {
      openSession();
      session.saveOrUpdate(data);
      session.flush();
    }
    catch(Exception e)
    {
      e.printStackTrace();
      sessionContext.setRollbackOnly();
      throw new DataManagerException(e);
    }
    finally
    {
      closeSession();
    }


The DistributionPlan is then returned to the client for further editing. The second time the client presses the save button, which triggers the above code on the server, changes made to objects linked to the DistributionPlan are not saved. Changes made to primitive properties of the DistributionPlan itself are always saved.

I would like to try not to change the hashCode and equals implementations of my objects. I have spent many hours testing them and have come up with implementations that do not cause recursion problems when checking collection properties but still provide accurate comparisons. I am afraid that changes to these methods will cause other parts of the program to break.

Any suggestions or advice, particularly comments that help me understand what is going on, would be appreciated.

John


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

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.