Hibernate / NHibernate: how to save a subclass as an instance of a superclass

I have two classes that I would like to save through NHibernate: - A cat that has a name and identifier, - A kitten, which is a subclass of Cat (no additional public properties).

For silly reasons, I would like to know if you can only schedule Cat? So when I save Kitten, it is saved as Cat, and when I reboot it, it boots as Cat.

Additional restrictions: - When trying, NHibernate crashed because he did not know Kitten. “However, I do not want to add the value of the discriminator, since I do not want Hibernate to create a subclass of Kitten.”

Many thanks!

EDIT: I forgot to write that using explicit ISession.Save ("Cat", kitten) works. My problem arises during cascading save.

+1
source share
1 answer

An old question, I probably have to use interfaces.

+1
source

Source: https://habr.com/ru/post/1750461/


All Articles