Is there any other information that I could provide that might help to diagnose this issue? I'm still unable to get this working.
Thanks. On Apr 30, 2:25 pm, Arthur Dent <[email protected]> wrote: > Ok, I realized why it was not letting me put the properties under the > main class. I didn't know that the order mattered and the > discriminator element needed to be before the properties. So that is > fixed now. I still get the same error though: > > > "The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has > > invalid child element 'discriminator' in namespace 'urn:nhibernate- > > mapping-2.2'. List of possible elements expected: 'property, many-to- > > one, one-to-one, component, dynamic-component, properties, any, map, > > set, list, bag, idbag, array, primitive-array, join, subclass, joined- > > subclass, union-subclass, loader, sql-insert, sql-update, sql-delete, > > filter, resultset, query, sql-query' in namespace 'urn:nhibernate- > > mapping-2.2'." > > This is my current mapping file: > > <?xml version="1.0" encoding="utf-8" ?> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > assembly="MyApp.DomainEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=01ca2278eac9ed50" namespace="MyApp.DomainEntities" > default-lazy="false"> > > <class name="IItinerary" table="Itinerary" abstract="true" > discriminator-value="A"> > <id name="Id" column="Id" type="Int32"> > <generator class="native" /> > </id> > <discriminator column="Movement" type="Char" /> > <many-to-one name="Personnel" column="PersonnelId" > class="Personnel"/> > <many-to-one name="ClassEnrollment" column="EnrollmentId" > class="ClassEnrollment"/> > <many-to-one name="Airline" column="AirlineId" class="Airline"/> > <property name="Movement" type="Char" access="readonly"/> > <property name="FlightNumber" type="String" /> > <property name="DepartureLocation" type="String" /> > <property name="DepartureTime" type="DateTime" /> > <property name="ArrivalLocation" type="String" /> > <property name="ArrivalTime" type="DateTime" /> > <property name="Instructions" column="SpecialInstructions" > type="String" /> > <property name="ModifiedDate" type="DateTime" /> > > <subclass name="InboundItinerary" discriminator-value="I" > lazy="false"> > </subclass> > <subclass name="OutboundItinerary" discriminator-value="O" > lazy="false"> > </subclass> > > </class> > </hibernate-mapping> > > On Apr 23, 5:02 pm, Arthur Dent <[email protected]> wrote: > > > > > > > > > Thanks for the response Marcelo! Ok, I have tried making the changes > > you suggested. I suppose you could say that putting the properties > > into the subclasses was by design, but I couldn't find any good > > information on how to implement this scenario in the NH > > documentation. My parent class is just an interface. I wasn't sure > > if I should use the "abstract=true" property for its tag either. It's > > not a true abstract class, but it's not a concrete class either. > > > When I try to put the common properties in the parent class > > (IItinerary) in the mapping, I get the following error: > > > "The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has > > invalid child element 'discriminator' in namespace 'urn:nhibernate- > > mapping-2.2'. List of possible elements expected: 'property, many-to- > > one, one-to-one, component, dynamic-component, properties, any, map, > > set, list, bag, idbag, array, primitive-array, join, subclass, joined- > > subclass, union-subclass, loader, sql-insert, sql-update, sql-delete, > > filter, resultset, query, sql-query' in namespace 'urn:nhibernate- > > mapping-2.2'." > > > Leaving the properties in the subclasses, and making the Movement > > field non-nullable doesn't fix the issue. I still get the same error: > > > "Object with id: 4 was not of the specified subclass: > > MyApp.DomainEntities.InboundItinerary (loading object was of wrong > > class [MyApp.DomainEntities.OutboundItinerary])" > > > Is there anything else that looks wrong in my configuration? > > > On Apr 20, 3:22 pm, Marcelo Grossi <[email protected]> wrote: > > > > Movement field should not be nullable. And also you have repeated > > > properties in your subclasses, is this by design? You should place the > > > common properties in the parent class.. it shouldn't matter if your > > > subclasses have no properties. > > > > -- > > > Marcelo Grossi > > > > On Apr 20, 4:23 am, Arthur Dent <[email protected]> wrote: > > > > > I'm trying to implement the table per class hierarchy model for > > > > itineraries in my app. I have a single Itinerary table, and the > > > > Movement field will have either an "I" or "O" as the discriminator for > > > > "inbound" or "outbound" itineraries. > > > > > I have set up an "IItinerary" interface to use as my parent class. > > > > Both InboundItinerary and OutboundItinerary classes implement this. > > > > They also inherit from a base Itinerary class, that in turn inherits > > > > from a BaseObject class that I use for most of the objects in my app. > > > > > The problem I'm having is that it doesn't seem to be able to determine > > > > what type of itinerary each record is when they get loaded. I get > > > > this error: > > > > "Object with id: 1 was not of the specified subclass: > > > > MyApp.DomainEntities.InboundItinerary (loading object was of wrong > > > > class [MyApp.DomainEntities.OutboundItinerary])" > > > > > Am I doing something wrong in my implementation? I found some similar > > > > issues while searching for an answer, and I turned off lazy loading > > > > because that seemed to fix it for some people. Is there something > > > > else I'm missing? > > > > > Itinerary Table > > > > ------------------------------------------------------ > > > > CREATE TABLE [dbo].[Itinerary]( > > > > [Id] [int] IDENTITY(1,1) NOT NULL, > > > > [EnrollmentId] [int] NOT NULL, > > > > [PersonnelId] [int] NULL, > > > > [AirlineId] [smallint] NOT NULL, > > > > [Movement] [char](1) NULL, > > > > [FlightNumber] [varchar](25) NOT NULL, > > > > [DepartureLocation] [varchar](25) NOT NULL, > > > > [DepartureTime] [smalldatetime] NOT NULL, > > > > [ArrivalLocation] [varchar](25) NOT NULL, > > > > [ArrivalTime] [smalldatetime] NOT NULL, > > > > [SpecialInstructions] [varchar](max) NULL CONSTRAINT > > > > [DF_Itinerary_Instructions] DEFAULT (space((0))), > > > > [ModifiedDate] [smalldatetime] NULL CONSTRAINT > > > > [DF_Itinerary_Date] > > > > DEFAULT (getdate()), > > > > CONSTRAINT [PK_Itinerary] PRIMARY KEY CLUSTERED > > > > ( > > > > [Id] ASC > > > > )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > > > > = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] > > > > ) ON [PRIMARY] > > > > ------------------------------------------------------ > > > > > Itinerary Mapping > > > > ------------------------------------------------------ > > > > <?xml version="1.0" encoding="utf-8" ?> > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > > > assembly="MyApp.DomainEntities, Version=1.0.0.0, Culture=neutral, > > > > PublicKeyToken=01ca2278eac9ed50" namespace="MyApp.DomainEntities" > > > > default-lazy="false"> > > > > > <class name="IItinerary" table="Itinerary" abstract="true" > > > > discriminator-value="A"> > > > > <id name="Id" column="Id" type="Int32"> > > > > <generator class="native" /> > > > > </id> > > > > > <discriminator column="Movement" type="Char" /> > > > > <subclass name="InboundItinerary" discriminator-value="I" > > > > lazy="false"> > > > > <many-to-one name="Personnel" column="PersonnelId" > > > > class="Personnel"/> > > > > <many-to-one name="ClassEnrollment" column="EnrollmentId" > > > > class="ClassEnrollment"/> > > > > <many-to-one name="Airline" column="AirlineId" class="Airline"/> > > > > > <property name="FlightNumber" type="String" /> > > > > <property name="DepartureLocation" type="String" /> > > > > <property name="DepartureTime" type="DateTime" /> > > > > <property name="ArrivalLocation" type="String" /> > > > > <property name="ArrivalTime" type="DateTime" /> > > > > <property name="Instructions" column="SpecialInstructions" > > > > type="String" /> > > > > <property name="ModifiedDate" type="DateTime" /> > > > > </subclass> > > > > <subclass name="OutboundItinerary" discriminator-value="O" > > > > lazy="false"> > > > > <many-to-one name="Personnel" column="PersonnelId" > > > > class="Personnel"/> > > > > <many-to-one name="ClassEnrollment" column="EnrollmentId" > > > > class="ClassEnrollment"/> > > > > <many-to-one name="Airline" column="AirlineId" class="Airline"/> > > > > > <property name="FlightNumber" type="String" /> > > > > <property name="DepartureLocation" type="String" /> > > > > <property name="DepartureTime" type="DateTime" /> > > > > <property name="ArrivalLocation" type="String" /> > > > > <property name="ArrivalTime" type="DateTime" /> > > > > <property name="Instructions" column="SpecialInstructions" > > > > type="String" /> > > > > <property name="ModifiedDate" type="DateTime" /> > > > > </subclass> > > > > > </class> > > > > </hibernate-mapping> > > > > ------------------------------------------------------ > > > > > IItinerary Interface > > > > ------------------------------------------------------ > > > > Public Interface IItinerary > > > > Property Airline() As Airline > > > > Property ArrivalLocation() As String > > > > Property ArrivalTime() As Nullable(Of DateTime) > > > > Property ClassEnrollment() As ClassEnrollment > > > > Property Personnel As Personnel > > > > ReadOnly Property Movement As Char > > > > Property ModifiedDate() As Nullable(Of DateTime) > > > > Property DepartureLocation() As String > > > > Property DepartureTime() As Nullable(Of DateTime) > > > > Property > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
