Hibernate version: 1.2.0.1001
Mapping documents: (2) Transaction & TransactionDetail
Overview: I have two classes, Transaction & TransactionDetail. Transaction contains a List(of TransactionDetail). I am having trouble saving a transaction.
______________________________________________
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="FinNHB" namespace="FinNHB">
<class name="Transaction" table="TransactionMaster" lazy="true">
<id name="TransactionID" column="TransactionID" type="Guid">
<generator class="guid.comb"/>
</id>
<property column="TransactionNumber" type="int" name="TransactionNumber" insert="false" not-null="true" />
<property column="FinancialYear" type="DateTime" name="FinancialYear" not-null="true" />
<property column="DateOccurred" type="DateTime" name="DateOccurred" not-null="true" />
<property column="DatePosted" type="DateTime" name="DatePosted" />
<property column="Reversal" type="int" name="Reversed" not-null="true" />
<property column="Comments" type="String" name="Comments" />
<bag name="TransactionDetails" inverse="false" cascade="all" lazy="true" >
<key column="TransactionID" />
<one-to-many class="TransactionDetail" />
</bag>
</class>
</hibernate-mapping>
____________________________________________
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="FinNHB" namespace="FinNHB">
<class name="TransactionDetail" table="TransactionDetail" lazy="true">
<id column="UniqueID" type="int">
<generator class="native"/>
</id>
<property column="Amount" type="Decimal" name="Amount" not-null="true" />
<property column="Debited" type="Boolean" name="IsAccountDebited" not-null="true" />
<property column="Reconciled" type="Boolean" name="Reconciled" />
<property column="Comments" type="String" name="Comments" />
<many-to-one name="TransactionID" column="TransactionID" class="Transaction" />
</class>
</hibernate-mapping>
____________________________________________
I have two tables in my database:
(1) TransactionMaster
PK=TransactionID(type=uniqueIdentifier)
IdentityColumn=TransactionNumber(type=int)
(2) TransactionDetail
PK, IdentityColumn=UniqueID(type=int)
FK, TransactionID(from transactionMaster)
_____________________________________________
I would like to do this:
Dim trns As New Transaction()
trns.DateOccurred = Today.AddYears(10)
trns.FinancialYear = Today.AddYears(10)
Dim detail As New TransactionDetail
detail.Amount = 333
detail.IsAccountDebited = True
Dim detail2 As New TransactionDetail
detail2.Amount = 444
detail2.IsAccountDebited = True
trns.TransactionDetails.Add(detail)
trns.TransactionDetails.Add(detail2)
transaction = session.BeginTransaction
session.Save(trns)
transaction.Commit()
__________________________________________
Error Message:
Could Not Save Object:
{"There is a problem with your mappings. You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>. \n\nA ValueType (System.Guid) can not be used with IdentityKey. The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey:
http://groups.google.com/groups?hl=en&l ... 26tab%3Dwg\r\nParameter name: key"}
__________________________________________
Help with this problem would be greatly appreciated. I have exhausted my application of the documentation and samples.