These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Let Nhibernate generate foreignkeys in one to many automatic
PostPosted: Fri Jan 30, 2009 8:40 pm 
Newbie

Joined: Thu Nov 20, 2008 10:44 am
Posts: 4
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 3:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look here:

http://nhforge.org/doc/nh/en/index.html#example-parentchild

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.