Can Hibernate's result transformer be used to map to related non-managed entities?

728 Views Asked by At

I have used ResultTransformer to map to simple non-managed entities, i.e that doesn't have relation to other entities. But I was wondering if it is possible through hibernate to map to a set of related non-managed entities? Just to make it clear, if I have set of non-managed entities like below,

Class A {
    private String a;

    List<B> bs;

    // getters and setters
}

Class B {
    private String b;

    List<C> cs;

    // getters and setters

}

Class C {
    private String c;

    // getters and setters
}

and I have a SQL like below,

select 
    a.a, 
    b.b, 
    c.c 
from 
    a 
    left join z on z.id = a.id 
    join b on b.id = z.id 
    left join c on b.id = c.id

then I would like to do something like

.setResultTransformer(Transformers.aliasToBean(A.class))

I know I can do this without ResultTransformer by going through returned data and populating the object graph myself. If I have to write that logic I would like to implement it as a custom ResultTransformer. Do you think it is sensible to do it that way?

Any ideas or help would be appreciated. Thanks!

0

There are 0 best solutions below