From: NHibernate J. <nh...@gm...> - 2008-09-18 22:16:25
|
[ http://jira.nhibernate.org/browse/NH-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16881#action_16881 ] Fabio Maulo commented on NH-662: -------------------------------- This and linked issue (NH-714) are probably obsolete in NH2.1.0 (the trunk) Please take a look to src\NHibernate.Test\DynamicEntity and confirm it. > Class Hierarchies > ----------------- > > Key: NH-662 > URL: http://jira.nhibernate.org/browse/NH-662 > Project: NHibernate > Issue Type: New Feature > Components: Core > Affects Versions: 1.2.0.Beta2 > Reporter: Anton Gogolev > Priority: Minor > Fix For: 2.1.0.Alpha1 > > > NH can only persist/load classes explicitly mapped to database tables in HBM files. On the one hand, this is quite logical. But on the other it limits further use of mapped classes. For instance, it is impossible to inherit from them and save the ancestor since its type is not mentioned anywhere in the mapping files. Here's an example: > // Base is mapped to, say, Base table in Base.hbm.xml > class Base > { > public int A > { get ...; set ... } > protected virtual Foo() > { > // Some logic. > } > } > // Derived has no mapping file > class Derived : Base > { > protected override Foo() > { > // Some other logic > } > } > static void Main() > { > ISession session = sessionFactory.OpenSession(); > Base base = new Base(); > base.A = 12; > session.Save(base); // This succeeds > base = session.Load(typeof(Base), 2) as Base; // This succeeds as well > base = new Derived(); // Note "Derived" here > base.A = 13; > session.Save(base); // And this fails > // We won't even get here, but if we did, > // this would have failed too > base = session.Load(typeof(Derived), 3) as Derived; > } > As you can see, the logic behind this is quite OOP-ish :) You inherit from some class to extend its functionality and state (in other words, functions and member variables). However, this is not possible with NHibernate, since it requires every derived class to be mapped somehow. > How I see it done (conceptually) is as follows. > Upon persisting an entity NH should traverse a list of base classes of the entity being persisted, until it finds a type which is mapped to a database table. This type is used to persist an entity. > When loading an entity from the database, NH can freely create an instance of derived class, since it is given its type (typeof(Derived) in the example above). Then again it traveses a list of base classes, and loads derived object as an object of base class. Of course some properties remain uninitialized, but that's not a problem, I think. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.nhibernate.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: NHibernate J. <nh...@gm...> - 2008-10-19 20:44:34
|
[ http://jira.nhibernate.org/browse/NH-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17071#action_17071 ] Fabio Maulo commented on NH-662: -------------------------------- If we want support this feature there is only 2 methods to change SessionFactoryImpl.GetEntityPersister(string) SessionFactoryImpl.TryGetEntityPersister(string) And the change is very trivial. I have some other doubt about the usability and security of this feature request. A persister know only one class to instantiate when you create a query... mmmm... have a persistent class without a specific mapping is not so good idea. > Class Hierarchies > ----------------- > > Key: NH-662 > URL: http://jira.nhibernate.org/browse/NH-662 > Project: NHibernate > Issue Type: New Feature > Components: Core > Affects Versions: 1.2.0.Beta2 > Reporter: Anton Gogolev > Priority: Minor > > NH can only persist/load classes explicitly mapped to database tables in HBM files. On the one hand, this is quite logical. But on the other it limits further use of mapped classes. For instance, it is impossible to inherit from them and save the ancestor since its type is not mentioned anywhere in the mapping files. Here's an example: > // Base is mapped to, say, Base table in Base.hbm.xml > class Base > { > public int A > { get ...; set ... } > protected virtual Foo() > { > // Some logic. > } > } > // Derived has no mapping file > class Derived : Base > { > protected override Foo() > { > // Some other logic > } > } > static void Main() > { > ISession session = sessionFactory.OpenSession(); > Base base = new Base(); > base.A = 12; > session.Save(base); // This succeeds > base = session.Load(typeof(Base), 2) as Base; // This succeeds as well > base = new Derived(); // Note "Derived" here > base.A = 13; > session.Save(base); // And this fails > // We won't even get here, but if we did, > // this would have failed too > base = session.Load(typeof(Derived), 3) as Derived; > } > As you can see, the logic behind this is quite OOP-ish :) You inherit from some class to extend its functionality and state (in other words, functions and member variables). However, this is not possible with NHibernate, since it requires every derived class to be mapped somehow. > How I see it done (conceptually) is as follows. > Upon persisting an entity NH should traverse a list of base classes of the entity being persisted, until it finds a type which is mapped to a database table. This type is used to persist an entity. > When loading an entity from the database, NH can freely create an instance of derived class, since it is given its type (typeof(Derived) in the example above). Then again it traveses a list of base classes, and loads derived object as an object of base class. Of course some properties remain uninitialized, but that's not a problem, I think. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.nhibernate.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: NHibernate J. <nh...@gm...> - 2009-06-16 05:44:34
|
[ http://nhjira.koah.net/browse/NH-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18236#action_18236 ] Fabio Maulo commented on NH-662: -------------------------------- I'm going to close this issue and the related issue (NH-714). In NH2.1.0 you have a lot of possibility to have this behaviour including the ability to query inherited classes. To be short: - entityName allow mapping a class more than one (and you can query it) - same mapping with different class name and polymorphic="explicit" work fine (even in NH1.2.1 if I remember well) - now you can inject behaviour using a IoC - perhaps the tuplizer can be used in some other situation > Class Hierarchies > ----------------- > > Key: NH-662 > URL: http://nhjira.koah.net/browse/NH-662 > Project: NHibernate > Issue Type: New Feature > Components: Core > Affects Versions: 1.2.0.Beta2 > Reporter: Anton Gogolev > Priority: Minor > > NH can only persist/load classes explicitly mapped to database tables in HBM files. On the one hand, this is quite logical. But on the other it limits further use of mapped classes. For instance, it is impossible to inherit from them and save the ancestor since its type is not mentioned anywhere in the mapping files. Here's an example: > // Base is mapped to, say, Base table in Base.hbm.xml > class Base > { > public int A > { get ...; set ... } > protected virtual Foo() > { > // Some logic. > } > } > // Derived has no mapping file > class Derived : Base > { > protected override Foo() > { > // Some other logic > } > } > static void Main() > { > ISession session = sessionFactory.OpenSession(); > Base base = new Base(); > base.A = 12; > session.Save(base); // This succeeds > base = session.Load(typeof(Base), 2) as Base; // This succeeds as well > base = new Derived(); // Note "Derived" here > base.A = 13; > session.Save(base); // And this fails > // We won't even get here, but if we did, > // this would have failed too > base = session.Load(typeof(Derived), 3) as Derived; > } > As you can see, the logic behind this is quite OOP-ish :) You inherit from some class to extend its functionality and state (in other words, functions and member variables). However, this is not possible with NHibernate, since it requires every derived class to be mapped somehow. > How I see it done (conceptually) is as follows. > Upon persisting an entity NH should traverse a list of base classes of the entity being persisted, until it finds a type which is mapped to a database table. This type is used to persist an entity. > When loading an entity from the database, NH can freely create an instance of derived class, since it is given its type (typeof(Derived) in the example above). Then again it traveses a list of base classes, and loads derived object as an object of base class. Of course some properties remain uninitialized, but that's not a problem, I think. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://nhjira.koah.net/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: NHibernate J. <nh...@gm...> - 2009-06-16 14:01:35
|
[ http://nhjira.koah.net/browse/NH-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18245#action_18245 ] Curtis Schlak commented on NH-662: ---------------------------------- Sounds great! Thanks for all of you hard work. > Class Hierarchies > ----------------- > > Key: NH-662 > URL: http://nhjira.koah.net/browse/NH-662 > Project: NHibernate > Issue Type: New Feature > Components: Core > Affects Versions: 1.2.0.Beta2 > Reporter: Anton Gogolev > Priority: Minor > > NH can only persist/load classes explicitly mapped to database tables in HBM files. On the one hand, this is quite logical. But on the other it limits further use of mapped classes. For instance, it is impossible to inherit from them and save the ancestor since its type is not mentioned anywhere in the mapping files. Here's an example: > // Base is mapped to, say, Base table in Base.hbm.xml > class Base > { > public int A > { get ...; set ... } > protected virtual Foo() > { > // Some logic. > } > } > // Derived has no mapping file > class Derived : Base > { > protected override Foo() > { > // Some other logic > } > } > static void Main() > { > ISession session = sessionFactory.OpenSession(); > Base base = new Base(); > base.A = 12; > session.Save(base); // This succeeds > base = session.Load(typeof(Base), 2) as Base; // This succeeds as well > base = new Derived(); // Note "Derived" here > base.A = 13; > session.Save(base); // And this fails > // We won't even get here, but if we did, > // this would have failed too > base = session.Load(typeof(Derived), 3) as Derived; > } > As you can see, the logic behind this is quite OOP-ish :) You inherit from some class to extend its functionality and state (in other words, functions and member variables). However, this is not possible with NHibernate, since it requires every derived class to be mapped somehow. > How I see it done (conceptually) is as follows. > Upon persisting an entity NH should traverse a list of base classes of the entity being persisted, until it finds a type which is mapped to a database table. This type is used to persist an entity. > When loading an entity from the database, NH can freely create an instance of derived class, since it is given its type (typeof(Derived) in the example above). Then again it traveses a list of base classes, and loads derived object as an object of base class. Of course some properties remain uninitialized, but that's not a problem, I think. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://nhjira.koah.net/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |