I've been having a mapping issue and seem to be getting this error even though I've checked my mapping files, classes, and database multiple times. I am attempting to do a unidirectional many to one mapping. Ironically, I do this in other places and I experience no issue. The error is 'Foreign key in table x_t_presences must have same number of columns as reference by primary key in table x_tx_addresses.
My table structure is as follows:
x_tx_addresses
Id (Pk)
City_Fk
State1_Fk
State2_Fk
Country_Fk
PostalCode_Fk
x_t_presences
Id (Pk)
Address (Fk) --Foreign key to x_tx_addresses Id
Address1
Address2
Address3
Lattitude
Longitude
I've included the mapping file below. This error is specific to when I add the many-to-one tag in the x_t_presences mapping file. Both classes have a primary Id property.
This seems pretty basic. Am I missing something really obvious?
Could this be something not okay with my database? I have other mapping files which do the same thing and do not cause this error.
The error occurs when I call BuildSessionFactory().
Thanks.
Hibernate version: 1.0.3
Database table script files
x_t_presences
CREATE TABLE [dbo].[x_t_presences](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Address_Fk] [int] NOT NULL,
[Address1] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Address2] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address3] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Lattitude] [float] NULL,
[Longitude] [float] NULL,
CONSTRAINT [PK_x_t_presences] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
x_tx_addresses
CREATE TABLE [dbo].[x_tx_addresses](
[Id] [int] IDENTITY(1,1) NOT NULL,
[City_Fk] [int] NOT NULL,
[State1_Fk] [int] NULL,
[State2_Fk] [int] NULL,
[Country_Fk] [int] NOT NULL,
[PostalCode_Fk] [int] NULL,
CONSTRAINT [PK_x_tx_addresses] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Mapping document:
<class name="TersoSolutions.ORLayer.Core.Extended.Presence" table="x_t_presences">
<id name="Id" type="int" column="Id">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<many-to-one access="field" name="address" column="Address_Fk" class="TersoSolutions.ORLayer.Core.Extended.Address"/>
<set name="Objects" table="tx_object_presences" lazy="true" access="NHibernate.Generics.GenericAccessor+CamelCase, NHibernate.Generics">
<meta attribute="scope-set">protected</meta>
<key column="kPresence"/>
<many-to-many class="TersoSolutions.ORLayer.Core.Object" column="kObject"/>
</set>
<property name="Address1" column="address1" type="string" length="100"/>
<property name="Address2" column="address2" type="string" length="100"/>
<property name="Address3" column="address3" type="string" length="100"/>
<property name="Lattitude" column="lattitude" type="float"/>
<property name="Longitude" column="longitude" type="float"/>
</class>
Full stack trace of any exception that occurs:
at NHibernate.Mapping.ForeignKey.set_ReferencedTable(Table value)
at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at TersoSolutions.ORLayer.ORSession.Session..ctor() in C:\TersoNextGen\ORLayer\ORSession\Session.cs:line 23
at TersoSolutions.ORLayer.ORSession.Session.CreateSession() in C:\TersoNextGen\ORLayer\ORSession\Session.cs:line 31
at ORLayerTester.Program.Main(String[] args) in C:\TersoNextGen\ORLayerTester\Program.cs:line 18
Name and version of the database you are using: SQL Server 2005
|