Submitted by david.w.boyd@saic.com
In developing a GUI/DB based application there needs to be a generic Map2Bean and Bean2Map set of conversions that will do deep (versus shallow) conversions.
For example, a UI based on BeanMetaObjects wants to persist it's results. The Hibernate module requires MapMetaObjects.
Using MetaObjectUtils.cloneMetaObject or copyMetaObject works if the metaobject does not contain other meta objects. Consider an object with the following instance variables:
private Long id;
private int sectionNumber;
private String courseId;
private String teacherId;
private ArrayList<Student> students;
private ArrayList<Assignment> assignments;
Since neither the clone or copy go deep any transition between hibernate and the ui requires custom bean2map and map2bean capabilities.
Logged In: YES
user_id=652870
Originator: NO
Just some general notes after investigating this a bit... it is a non-trivial operation.
Issue 1: properly detecting all nested meta-objects is tricky at best. The best we could do would be to handle the obvious cases: direct references and collections.
Issue 2: Since clone delegates to copy, we'd need an alternate copy method that knows the destination objects need to be created. In other words, any nested meta-objects need to be cloned instead of having their values copied directly.
Also, internally we'd need a Map to track which objects we'd already cloned.
Deep cloning is a problem that is hard to solve even in Java objects and the sure-fire way is usually to resort to serialization. In that spirit, it may in fact be easier to just create a deep clone method that uses serialization to do the job... then we'd get a chance to recreate every meta-object encountered and convert them to a different MetaKit.
Note: the fact that hibernate currently only supports MapMetaObjects is a separate issue and one I'd like to fix if we can at some point.