views:

49

answers:

1

For some reason the following mapping seems to be creating me a very strange column name that I cant find anywhere. There error occures when trying to load the Events collection which is defined as a IList<Event>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="JeanieMaster.Domain.Entities" assembly="JeanieMaster.Domain">
  <class name="Location" table="Location" select-before-update="false" optimistic-lock="none">
    <id name="Id" column="LocationId" type="Int32">
      <generator class="identity"/>
    </id>
    <property name="CompanyName" type="String" />
    <property name="AddressLine1"  type="String" length="220" />
    <property name="AddressLine2"  type="String" length="220" />
    <property name="City" type="String" length="220" />
    <property name="Postcode" type="String" length="15" />
    <property name="County" type="String" length="220" />
    <property name="TelephoneNumber" type="String" length="25" />
    <property name="Latitude" type="Double" />
    <property name="Longitude" type="Double" />
    <property name="CreatedOn" type="DateTime" />
    <property name="ModifiedOn" type="DateTime" />

    <bag name="Events" table="VolatileEventContent" where="DeactivatedOn IS NULL" order-by="StartDate DESC" lazy="false" cascade="none">
      <key column="LocationId"/>
      <many-to-many class="Event"></many-to-many>
    </bag>
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="JeanieMaster.Domain.Entities" assembly="JeanieMaster.Domain">
  <class name="Event" table="VolatileEventContent" select-before-update="false" optimistic-lock="none">
    <id name="Id" column="VolatileContentEventId" type="Int32">
      <generator class="identity"/>
    </id>

    <property name="Description" type="String" not-null="true" update="false" insert="false"/>

    <property name="StartDate" type="DateTime" not-null="true" />
    <property name="EndDate" type="DateTime" not-null="true" />

    <property name="CreatedOn" type="DateTime" not-null="true" />
    <property name="ModifiedOn" type="DateTime" />

    <many-to-one name="Location" class="Location" column="LocationId" />

    <bag name="Artists" table="EventArtiste" lazy="false" cascade="none">
      <key column="EventId"/>
      <many-to-many class="Artiste" column="ArtisteId" ></many-to-many>
    </bag>
  </class>
</hibernate-mapping>

The generated SQL is very strange as its self joining on a column "elt" which doesnt exist

SELECT          events0_.LocationId as LocationId__1_, 
                events0_.elt as elt1_, 
                event1_.VolatileContentEventId as Volatile1_12_0_, 
                event1_.Description as Descript2_12_0_, 
                event1_.StartDate as StartDate12_0_, 
                event1_.EndDate as EndDate12_0_, 
                event1_.CreatedOn as CreatedOn12_0_, 
                event1_.ModifiedOn as ModifiedOn12_0_, 
                event1_.LocationId as LocationId12_0_ 
FROM            VolatileEventContent events0_ 
left outer join VolatileEventContent event1_ 
on              events0_.elt=event1_.VolatileContentEventId 
WHERE           events0_.DeactivatedOn = NULL 
and             events0_.LocationId=184244 
ORDER BY        events0_.StartDate

This is my table definition:

CREATE TABLE [dbo].[VolatileEventContent](
    [VolatileEventContentId] [int] IDENTITY(1,1) NOT NULL,
    [LocationId] [int] NOT NULL,
    [CategoryId] [int] NULL,
    [ContentProviderId] [int] NOT NULL,
    [Description] [nvarchar](4000) NOT NULL,
    [StartDate] [datetime] NOT NULL,
    [EndDate] [datetime] NOT NULL,
    [CreatedOn] [datetime] NOT NULL,
    [ModifiedOn] [datetime] NULL,
    [DeactivatedOn] [datetime] NULL,
 CONSTRAINT [PK_VolatileEventContent] PRIMARY KEY CLUSTERED 
(
    [VolatileEventContentId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[VolatileEventContent]  WITH CHECK ADD  CONSTRAINT [FK_VolatileEventContent_ContentProvider] FOREIGN KEY([ContentProviderId])
REFERENCES [dbo].[ContentProvider] ([ContentProviderId])
GO

ALTER TABLE [dbo].[VolatileEventContent] CHECK CONSTRAINT [FK_VolatileEventContent_ContentProvider]
GO
A: 

Hmm strange I dont know why it was doing the above but I realised there was 2 things wrong with my hbm files

1) VolatileContentEventId should have been VolatileEventContentId in the primary key declaration of the Event

2) I have also added column="VolatileEventContentId" to the key of the child event entity

tigermain