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?