dpmihai,
The problem is traversing associations (a.getB().getC() etc).
Imagine your mapping file contains classes A, B, C, etc where A has a collection of B i.e. class A has a method getBs() which returns a collection of B objects.
Let's say you can not modify the source code for A,B,C etc because they are generated by a tool. So you create classes A1, B1, C1 which extend (or contain) A,B,C with your "extra methods".
Now you obviously want A1 getB1s() method to return a collection of B1 objects not B objects but how do you do this?
The only way is to have to write wrappers for every accessor which is a very ugly design (even if you use code generators). You could do this:
Code:
public class A1 {
private A a;
public Set<B1> getB1s() {
Set<B> hibSet = a.getBs();
Set<B1> newSet = new HashSet();
for( B in hibSet ) { // yuk, forces load of whole set!
newSet.add( new B1(B) );
}
return newSet;
}
}
This is a very bad solution: it would be a performance disaster by doubling the number of objects on the heap and forcing the loading of entire associations.
Ben