Hi,
I have a really annoying error which I can't figure out:
"Foreign key in table Tests must have same number of columns as referenced primary key in table Tests"
Parts is Tests parent, but should parts have the "whole" combined key to work?
I am really close to giving up since the mappings have caused so many errors :(
I hope some of your experts can help.
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="data.Tests,data" table="Tests">
<composite-id>
<key-many-to-one name="FKPartsId" column="PartsID" class=".data.Tests,.data"/>
<key-property name="TestOrderId" column="TestOrderID" />
</composite-id>
<property column="TestID" type="Guid" name="Testid" not-null="true" />
<property column="TestName" type="String" name="TestName" not-null="true" length="150" />
<property column="CreationDate" type="DateTime" name="CreationDate" not-null="true" />
<property column="Author" type="String" name="Author" not-null="true" length="50" />
<property column="EditDate" type="DateTime" name="EditDate" />
<property column="EditAuthor" type="String" name="EditAuthor" length="50" />
<property column="BinaryTestID" type="Int32" name="BinaryTestid" />
<property column="MainTestID" type="Int32" name="MainTestid" />
<set
name="PartsId"
inverse="true"
cascade="all-delete-orphan">
<key column="PartsID"/>
<one-to-many class="data.Parts, data"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
private void InitSessionFactory()
{
Configuration cfg = new Configuration();
cfg.AddAssembly("data");
factory = cfg.BuildSessionFactory();
}
Full stack trace of any exception that occurs:
" at NHibernate.Mapping.ForeignKey.set_ReferencedTable(Table value)\r\n at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)\r\n at NHibernate.Cfg.Configuration.SecondPassCompile()\r\n at NHibernate.Cfg.Configuration.BuildSessionFactory()\r\n at data.SessionFactorySingleton.InitSessionFactory() in C:\\xxx:line 44\r\n at data.SessionFactorySingleton..ctor() in C:\\xx 19\r\n at data.SessionFactorySingleton.get_Instance() in xx31\r\n at data.Programs.getProgramId(Int32 ProgramID) in xx168\r\n at HibernateTest.Form1.PopulateData(Int32 runs) in xx
60\r\n at HibernateTest.Form1.Form1_Load(Object sender, EventArgs e) in xx104\r\n at System.Windows.Forms.Form.OnLoad(EventArgs e)\r\n at System.Windows.Forms.Form.OnCreateControl()\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl()\r\n at System.Windows.Forms.Control.WmShowWindow(Message& m)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n at System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n at System.Windows.Forms.Form.WmShowWindow(Message& m)\r\n at System.Windows.Forms.Form.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)\r\n at System.Windows.Forms.Control.SetVisibleCore(Boolean value)\r\n at System.Windows.Forms.Form.SetVisibleCore(Boolean value)\r\n at System.Windows.Forms.Control.set_Visible(Boolean value)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at HibernateTest.Program.Main() in Cxx
7\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"
Name and version of the database you are using:
MSSQL 2000
"Foreign key in table Tests must have same number of columns as referenced primary key in table Tests"
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html