[Updated with mapping files]
Ran into an issue with a lazy loaded / proxied object being persisted today.
It relates to two classes, Invoice and Address. A invoice has an Address property. Both classes are setup to be lazy loaded and all methods are virtual.
In the code I do a Invoice.address = HomeCompany.address and I can verify at runtime that the Invoice.address is being set correctly (The Invoice.address property is correctly assigned an 'address proxy'). However when the Invoice object gets persisted, the 'addresss_id' columns in the invoice table is being set to '0'. If however, i change the mapping file for the address by adding 'Lazy = False' everything works just fine (the invoice.address property is set to a full instantiated address).
Using nHibernate 2.1.2 and this is driving me crazy.
[Note: nhibernate is not generating any errors]
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping default-access="field.camelcase-underscore" xmlns="urn:nhibernate-mapping-2.2">
<class name="TMS.Business.invoice, TMS.Business" dynamic-update="true" optimistic-lock="all" table="invoice">
<id name="document_id" type="Int32">
<generator class="assigned" />
</id>
<property name="create_date" />
<many-to-one name="last_updt_user" column="last_updt_userid"/>
<property name="last_updt_datetime" />
<property name="amount" />
<property name="approved_flag"/>
<property name="ba_document_date" />
<property name="ba_document_no" not-null="true"/>
<property name="comment" not-null="true"/>
<property name="document_no" />
<property name="document_no_construct"/>
<property name="dry_gas_billing_date" />
<property name="due_date" />
<property name="fin_batch_no" />
<property name="fin_interface_type_cd"/>
<property name="fin_process_datetime" />
<property name="invoice_date" />
<property name="netout_flag"/>
<property name="override_amount" />
<property name="receipt_date" />
<property name="void_flag"/>
<many-to-one name="accountant_user" column="accountant_userid"/>
<many-to-one name="ba" column="ba_id" property-ref="_ba_id" />
<many-to-one name="ba_addr" column="ba_addr_id" property-ref="_ba_address_id" />
<many-to-one name="ba_contact" column="ba_contact_id" property-ref="_ba_contact_id" />
<many-to-one name="dry_gas_billing_type" column="dry_gas_billing_type_cd" property-ref="_code_key" />
<many-to-one name="internal_ba" column="internal_ba_id" property-ref="_ba_id" />
<many-to-one name="invoice_subtype" column="invoice_subtype_cd" property-ref="_code_key" />
<many-to-one name="invoice_type" column="invoice_type_cd" property-ref="_code_key" />
<many-to-one name="payment_method" column="payment_method_cd" property-ref="_code_key" />
<many-to-one name="payment_term" column="payment_term_id" />
<many-to-one name="remit_to_addr" column="remit_to_addr_id" property-ref="_ba_address_id"/>
<bag name="document_histories" lazy="true" cascade="none" inverse="true" where ="linked_table = 'invoice'" order-by="document_history_id DESC">
<key column="linked_pk"/>
<one-to-many class="TMS.Business.document_history, TMS.Business"/>
</bag>
<bag name="trxn_pricelines" lazy="true" cascade="none" inverse="true">
<key column="document_id"/>
<one-to-many class="TMS.Business.trxn_priceline, TMS.Business"/>
</bag>
</class>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping default-access="field.camelcase-underscore" xmlns="urn:nhibernate-mapping-2.2">
<class name="TMS.Business.ba_address, TMS.Business" optimistic-lock="version" table="_ba_address">
<id name="item_guid" type="Guid">
<generator class="guid" />
</id>
<version name="version" />
<property name="active_flag" />
<property name="address" />
<property name="city" />
<property name="county" />
<property name="remarks" />
<property name="zip" />
<many-to-one name="business_associate" column="business_associate_guid" />
<many-to-one name="country" column="country_code" />
<many-to-one name="state" column="state_code" />
<property name="_ba_address_id" generated="insert" update="false" insert="false"/>
</class>