Hibernate/NHibernate : how to persist subclass as instance of superclass

删除回忆录丶 提交于 2019-12-13 18:04:41

问题


I have two classes I would like to persist via NHibernate: - Cat, which has a name and an Id, - Kitten, which is a subclass of Cat (no extra public properties).

For stupid reasons, I would like to know if it is possible to map Cat only? So that when I persist Kitten, it is saved as a Cat and when I reload it, it is loaded as a Cat.

Additional constraints : - When trying, NHibernate crashed because it did not know Kitten. - However I do not want to add a discriminator value, as I do not want Hibernate to instantiate the Kitten subclass.

Thank you very much!

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


回答1:


Old question, I guess I would have to use interfaces instead.



来源:https://stackoverflow.com/questions/852629/hibernate-nhibernate-how-to-persist-subclass-as-instance-of-superclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!