Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:2.2
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BusinessLayer.Claims" assembly="BusinessLayer">
<class name="ServiceAdjudications" table="ClaimAdjudicationServices" >
<id name="ID" column="ClaimAdjudicationServicesKey" type="Int32">
<!--<id name="ID">-->
<generator class="native"/>
</id>
<property name="DOSStart" column="DateOfServiceStart" type="Date"/>
<property name="DOSEnd" column="DateOfServiceEnd" type="Date"/>
<property name="CPTCode" column="ServiceProcedureCode" type="String"/>
<property name="Modifier" column="ServiceModifierCode" type="String"/>
<property name="Billed" column="LineItemChargeAmount" type="Decimal"/>
<property name="Allowed" column="ServiceAllowedAmount" type="Decimal"/>
<property name="UnitPaid" column="ServiceUnitsPaid" type="Decimal"/>
<property name="AmountPaid" column="ServiceAmountPaid" type="Decimal"/>
<property name="ClaimsKey" column="ClaimsKey" type="Int32"/>
<set name="Adjustments" cascade="all">
<key column="AdjudicationServiceAdjustmentsKey"/>
<one-to-many class="ServiceAdjustments"/>
</set>
<set name="Remarks" cascade="all">
<key column="AdjudicationServiceRemarksKey" />
<one-to-many class="ServiceRemarkCodes"/>
</set>
</class>
</hibernate-mapping>
Mapping documents:<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BusinessLayer.Claims" assembly="BusinessLayer">
<class name="ServiceAdjustments" table="AdjudicationServiceAdjustments">
<id name="ID" column="AdjudicationServiceAdjustmentsKey" type="Int32">
<generator class="native"/>
</id>
<property name="GroupCode" column="AdjustmentGroupCode" type="String"/>
<property name="ReasonCode" column="AdjustmentReasonCode" type="String"/>
<property name="MonetaryAmount" column="AdjustmentMonetaryAmount" type="Decimal"/>
<property name="ClaimAdjudicationServicesKey" column="ClaimAdjudicationServicesKey" type="Int32" generated="insert"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
ClaimAdjudicationsDAO ClaimAdjudicationsFactory = new ClaimAdjudicationsDAO();
ClaimAdjudicationsFactory.Insert(ClaimAdjudicationsClass);
ClaimAdjudicationsFactory.CloseSession();
[b]
public class ServiceAdjudications
{
public virtual int ID { get; set; }
public virtual DateTime DOSStart { get; set; }
public virtual DateTime DOSEnd { get; set; }
public virtual string CPTCode { get; set; }
public virtual string Modifier { get; set; }
public virtual decimal Billed { get; set; }
public virtual decimal Allowed { get; set; }
public virtual decimal UnitPaid { get; set; }
public virtual decimal AmountPaid { get; set; }
public virtual int ClaimsKey { get; set; }
public virtual ISet Adjustments { get; set; }
public virtual ISet Remarks { get; set; }
}
public class ServiceAdjustments
{
public virtual int ID { get; set; }
public virtual string GroupCode { get; set; }
public virtual string ReasonCode { get; set; }
public virtual decimal MonetaryAmount { get; set; }
}
I instantiate a collection of ServiceAdjustments and I add it to ServiceAdjudications and when I try to save, it hangs out and it's telling me that I can have null value for the foreignkey in ServiceAdjustments table. How do can I have Nhibernate populate the foreignkey automatically?
I don't know how to save an ISet collection of ServiceAdjustments, can somebody help me figure this out please, please, please, please.
Thank you so much.