c# - How to manage a multiple-level class hierarchy in nhibernate with table per class hierarchy strategy? -
I'm trying to implement my object hierarchy in a table with "Table NHibernate class hierarchy to" strategy . I am getting an error with my NHibernate mapping which can easily be reproduced with a simple example. Error:
System.NotSupportedException: is trying to parse a zero value in a SQL string (: activity0_.Type column). Line 551
I line NHibernate.Persister.Entity.SingleTableEntityPersister.DiscriminatorFilterFragment (String alias) at 109: NHibernate.SqlCommand.InFragment.ToFragmentString (in SingleTableEntityPersister.cs) in InFragment.cs It can reproduce with at least the following domain classes:
Public Interface IActivity {Guid Id {get; Set; }} Public class class activity: IActivity {public date timeline {get; Set; } Get Public Guide ID { Set; }} Running public class: activity {public string where {get; Set; }} Talking public class: activity {public string towhom {get; Set; }}
and the following XML mapping:
& lt ;? XML version = "1.0"? & Gt; & Lt; Hibernate-mapping xmlns = "urn: nhibernate- mapping -2.2" Assembly = "NHibernateTesting" namespace = "NHibernateTesting" & gt; & Lt; Class name = "IActivity" lazy = "false" table = "activity" discriminator-value = "0" abstract = "true" & gt; & Lt; ID name = "id" & gt; & Lt; Generator class = "guid" /> & Lt; / Id & gt; & Lt; Discriminator column = "type" type = "int16" /> & Lt; Subclass name = "activity" discriminating-value = "1" table = "true" lazy = "wrong" & gt; & Lt; Property Name = "Start Time" /> & Lt; / Subclass & gt; & Lt; Subclass name = "running" discriminator-value = "2" lazy = "false" extended = "activity" & gt; & Lt; Property Name = "Where" /> & Lt; / Subclass & gt; & Lt; Subclass name = "talking" discriminator-value = "3" lazy = "false" extended = "activity" & gt; & Lt; Property Name = "ToWhom" /> & Lt; / Subclass & gt; & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;
Anyone have an idea of what I'm doing wrong?
I am not familiar with C # and NHibernate, but are you sure that action < / Code> should be set in the mapping form as
abstract = "true"
? It seems that the activity class is not abstract.
should not be running running
and
talking activity
and some start time will not be saved. right?
& lt; Subclass name = "activity" ... & lt; Subclass name = "Running" ... & lt; / Subclass & gt; & Lt; Subclass name = "Talking" ... & lt; / Subclass & gt; ... & lt; / Subclass & gt;
The error message in any way indicates that NHibernate is trying to create some queries with an in-statement but there is no value for it, basically it is something to do tries like
... WHERE foo iN (null)
If I parse correctly the code
Are you already trying to enable them in hibernate-configurations to check what is happening?
& lt; Property Name = "show_sql" & gt; True & lt; / Property & gt; & Lt; Property Name = "hibernate.format_sql" & gt; True & lt; / Property & gt; & Lt; Property Name = "hibernate.use_sql_comments" & gt; True & lt; / Property & gt;
Comments
Post a Comment