Hi, New to nhibernate. I've been looking at examples all day and trying to get my composite id correct, but I am really having trouble. I hope you can help. Here is my mapping. The table has 4 fields that make up the composite key, and one additional 5th field. Only 3 of the 4 fields are related to other tables, and "Date_Used" is the one that has no relation. It's just a date.
This is the closest I can get it to what i think is right:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="EmployeeTimeTracker.EmpTime, EmployeeTimeTracker" table="dbo.EMPLOYEE_TIME_USED">
<composite-id name="EmpTimeKey" class="EmpTimeKey">
<key-many-to-one name="EmpID" class="Employee" column="EMPLOYEEID" insert="false" update="false" />
<key-many-to-one name="TimeType" class="TimeType" column="TIME_ID" insert="false" update="false" />
<key-many-to-one name="AttendReason" class="AttendReason" columne="REASON_ID" insert="false" update="false" />
<key-property name="DateUsed" column="DATE_USED" />
</composite-id>
<property name="HoursUsed" column="HOURS_USED" />
</class>
</hibernate-mapping>
The error i am getting is as follows, during runtime when NHibernate is reading the mapping files:
[error]
"The element 'urn:nhibernate-mapping-2.2:composite-id' cannot contain text. Expected 'urn:nhibernate-mapping-2.2:key-property urn:nhibernate-mapping-2.2:key-many-to-one'. An error occurred at , (4, 54).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Xml.Schema.XmlSchemaException: The element 'urn:nhibernate-mapping-2.2:composite-id' cannot contain text. Expected 'urn:nhibernate-mapping-2.2:key-property urn:nhibernate-mapping-2.2:key-many-to-one'. An error occurred at , (4, 54)."
[/error]
Is it just my syntax? What does "error occurred at (4, 54)" mean?
Must the mapping files for the classes/components related to these "many-to-one" fields, also have coordinating "one-to-many" tags?
I know this is my problem, bcz i already had everything working, ie, using nh to pull back data. It was when I went to do my update routine, that I realized i needed this composite key, so I could query this table for one, precise record. I want it this way so that I can use HQL to query for the record, update the live object and flush it. Thanks for any help. Although it's a bit agonizing getting started, this is really awesome and powerful technology,and I can't wait to get it fully functional.