简体   繁体   中英

NHibernate base and derived class mapping

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?

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.

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"> ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM