These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Foreign key in table must have same number of columns
PostPosted: Thu Feb 14, 2008 7:44 am 
Beginner
Beginner

Joined: Mon Jan 21, 2008 8:57 am
Posts: 20
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.