-->
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: Sort nested object collection in persisted object?
PostPosted: Fri Jan 28, 2011 11:04 am 
Newbie

Joined: Wed Oct 06, 2010 1:35 pm
Posts: 6
What is the best way (or is there a way at all) to sort a collection attached to a persisted object? I have a collection inside a persisted object mapped this way:

Code:
   
@OneToMany(mappedBy = "worksheetHeader", cascade=CascadeType.ALL)
private List<WorksheetVehicle> vehicles = new ArrayList<WorksheetVehicle>();


I attempted to sort the contents in the getter before returning them:
Code:
   public List<WorksheetVehicle> getVehicles() {
      Collections.sort(vehicles, WorksheetVehicle.vehicleSortByYMM() );
      return vehicles;
        }


But this caused a problem. When DELETING a record, not all rows in the nested collection are deleted. I have stepped through the code and I believe that the problem is internal to the Hibernate Cascade class, specifically this code:
Code:
         Iterator iter = action.getCascadableChildrenIterator(eventSource, collectionType, child);
         while ( iter.hasNext() ) {
            cascadeProperty(
                  iter.next(),
                  elemType,
                  style,
                  anything,
                  isCascadeDeleteEnabled
               );
         }


When the Cascade class attempts to iterate over the sorted collection, it does not seem to produce the expected result (i.e., not all rows are deleted).

Is this a known problem or limitation, or am I doing something wrong?


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.