views:

269

answers:

2

Situation: I have a class MyClass and its "lightweight" version MyClassLite, so i have

public class MyClass : MyClassLite

I also use hbm file for mapping my classes (they are mapped to the same table). The thing is that when i try to get a list of MyClassLite entities, i get not only MyClassLite entities, but a list of MyClass entities moreover. How can i rid of that?

A: 

If you configure eager loading for the list in the mapping or in the query, you will get the MyClass implementation.

In a criteria query:

Criteria.SetFetchmode("MyClassListProperty", Fetchmode.Eager)

in an hql query:

left join fetch MyClassListProperty

in the mapping file:

<set [...] lazy="false"> ...
Jan Willem B
+1  A: 

What exactly is this ClassLite ? Why does your Class inherit from ClassLite ? Is there really an 'IS-A' relationship here ?

What is the reason of existence for ClassLite ? Is it a class which you use when, for instance, you have to display an overview of 'Class' instances ? Then, if this is the case, you should have a look at DTO's or 'Views', Projections and the AliasToBeanEntityResultTransformer.

Frederik Gheysels