Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.0.2
Mapping documents:
For Account
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DirectBill.Common.Domain.Account,DirectBill.Common" table="tblAccount">
<id name="AcctId" column="ACCT_ID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<version column="CHANGEID" type="Int32" name="Changeid" unsaved-value="0" />
<bag name="AccountHistoryList" inverse="false" lazy="false" >
<key column="ACCTID" />
<one-to-many class="DirectBill.Common.Domain.AccountHistory,DirectBill.Common" />
</bag>
<bag name="AcctStatusList" inverse="false" lazy="false" table="tblAcctStatus">
<key column="ACCTID" />
<many-to-many class="DirectBill.Common.Domain.AcctStatusType,DirectBill.Common" column="ACCTSTATUSID" />
</bag>
<bag name="ANIAccessList" inverse="true" lazy="true" >
<key column="ACCT" />
<one-to-many class="DirectBill.Common.Domain.ANIAccess,DirectBill.Common" />
</bag>
<bag name="BillingInformationList" inverse="true" lazy="false" >
<key column="ACCT" />
<one-to-many class="DirectBill.Common.Domain.BillingInformation,DirectBill.Common" />
</bag>
<bag name="BlockHistoryList" inverse="true" lazy="true" >
<key column="ACCT" />
<one-to-many class="DirectBill.Common.Domain.BlockHistory,DirectBill.Common" />
</bag>
<bag name="TransactionList" inverse="true" lazy="false" >
<key column="ACCT" />
<one-to-many class="DirectBill.Common.Domain.Transaction,DirectBill.Common" />
</bag>
<property column="ANI" type="String" name="ANI" length="10" />
<many-to-one name="Currentbilling" column="CURRENTBILLING" class="DirectBill.Common.Domain.BillingInformation,DirectBill.Common" />
<property column="LASTCONTACT" type="DateTime" access="field" name="m_lastcontact"/>
<property column="NOTES" type="String" name="Notes" length="256" />
<property column="PASSWORD" type="String" name="Password" length="50" />
</class>
</hibernate-mapping>
For transaction
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DirectBill.Common.Domain.Transaction,DirectBill.Common" table="tblTransaction">
<id name="TransactionID" column="TRANSACTIONID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="Acct" column="ACCT" insert="true" class="DirectBill.Common.Domain.Account,DirectBill.Common" />
<many-to-one name="Transactiontypeid" column="TRANSACTIONTYPEID" class="DirectBill.Common.Domain.TransactionType,DirectBill.Common" />
<many-to-one name="Enteredby" column="ENTEREDBY" class="DirectBill.Common.Domain.User,DirectBill.Common" />
<property column="TRANSACTIONDATE" type="DateTime" access="field" name="m_TransactionDate" />
<property column="ISCREDIT" type="Boolean" name="Iscredit" />
<property column="AMOUNT" type="Decimal" name="Amount" />
<property column="TRANSACTIONCLEARED" type="Boolean" name="Transactioncleared" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
This may the problem, my code spans two sessions. First I use a session to retrieve an account. I then set the ACCT property of my Transaction to that account I retrieve. Finally I save the Transaction. When I look at the database, everything is properly persisted except for the reference to the account (the acct column). When looking at the generated SQL, I can see the ACCT parameter being made but the value passed in is '' . Do I need to change my code to handle all of this in one session or is there a bug here?
Full stack trace of any exception that occurs: No Exception
Name and version of the database you are using: MSSQL 2005 Standard
Can someone provide some advice on how to make this work properly?