-->
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.  [ 3 posts ] 
Author Message
 Post subject: composite-id struggles
PostPosted: Sat Nov 12, 2005 2:24 pm 
Newbie

Joined: Sat Nov 12, 2005 2:17 pm
Posts: 2
I'm really struggling with my composite-id mapping. It seems to be loading everything, but the Violations list never gets populated with anything. It's always empty. It also seems to be hitting the database a lot for the same information. Could someone please help?

Policy.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Business.Policy, Business" table="policy">
      <composite-id>
         <key-property name="PolicyNum" column="policy_num" />
         <key-property name="PolicySym" column="policy_sym" />
         <key-property name="PolicyMod" column="policy_mod" />
         <key-property name="PolicyMco" column="policy_mco" />
      </composite-id>
      <property name="EffectiveDate" column="eff_date" />
      <property name="PrimaryState" column="prim_state_code" />

      <bag name="Violations" inverse="true" lazy="false" cascade="all">
         <key>
            <column name="policy_num" not-null="true" />
            <column name="policy_sym" not-null="true" />
            <column name="policy_mod" not-null="true" />
            <column name="policy_mco" not-null="true" />
         </key>
         <one-to-many class="Business.Violation, Business" />
      </bag>
   </class>
</hibernate-mapping>


Violation.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Business.Violation, Business" table="violation">
      <id name="ViolationId" type="System.Int32" column="violation_seq" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="PersonId" column="person_seq" not-null="true" />
      <property name="CovPartTypeCode" column="cov_part_type_code" not-null="true"  />
      <property name="PolicyNum" column="policy_num" insert="false" update="false" />
      <property name="PolicySym" column="policy_sym" insert="false" update="false" />
      <property name="PolicyMod" column="policy_mod" insert="false" update="false" />
      <property name="PolicyMco" column="policy_mco" insert="false" update="false" />
      <property name="ViolationNum" column="violation_num" />
      <property name="ViolationDate" column="date" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
      <property name="ViolationTypeCode" column="acc_violation_type_code" />
      <property name="Description" column="descript" />
      <property name="Amount" column="amt" />
      <property name="ModifiedUserId" column="modified_user_id" not-null="true" />
      <property name="ModifiedDate" column="modified_date" not-null="true" />
      <property name="ClaimStatus" column="claim_status" />

      <many-to-one name="Policy" class="Business.Policy, Business" not-null="true">
         <column name="policy_num" />
         <column name="policy_sym" />
         <column name="policy_mod" />
         <column name="policy_mco" />
      </many-to-one>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 13, 2005 4:54 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Could you post your class code? Did you implement Equals and GetHashCode, and make your key class Serializable?


Top
 Profile  
 
 Post subject: Overloading AND Overriding
PostPosted: Mon Nov 14, 2005 12:00 am 
Newbie

Joined: Sat Nov 12, 2005 2:17 pm
Posts: 2
Your reply caused me to look a little deeper at my composite id class, and sure enough, that was the problem. I'm using VB.NET for this particular application, and I was only Overloading Equals() and GetHashCode(), not Overriding.

I modified my code so that GetHashCode() was declared with Overrides and Equals() with both Overloads and Overrides.

It's all working great now.

Thanks!

NHibernate rocks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.