-->
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.  [ 1 post ] 
Author Message
 Post subject: Multiple children are the same record
PostPosted: Tue Jun 26, 2007 2:11 pm 
Newbie

Joined: Tue Jun 26, 2007 12:37 pm
Posts: 10
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:NHibernate 1.2.0.4

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property">
<class name ="NHibernateTest.PropertyRecord, NHibernateTest" table="OPR_Logi_Documents" where="LastUpdated_Date >= '5/17/2007'">
<id name ="Id" column="INSTRUMENT_NUMBER">
<generator class ="assigned" />
</id>
<property name ="DocumentType" column="Document_Type"/>
<property name ="Book" column="book"/>
<property name ="Page" column="page"/>
<property name ="MicrofilmCode" column="Multi_Seq"/>
<property name ="ClerkRecorderUnparsedName" column="SCANNED_BY"/>
<property name ="CreateDate" column="DOCUMENT_DATE"/>
<property name ="ModifiedDate" column="LASTUPDATED_BY"/>
<property name ="SequenceNumber" column="Instrument_Number"/>
<property name ="OtherDocumentType" column="Document_Type"/>
<property name="OtherDescription" column="Scanned_By"/>
<bag name="Grantors" table="OPR_Parties" where="Name_Type = 'R'" cascade="none" fetch="subselect" lazy="false" inverse="true">
<key column="Instrument_Number"/>
<one-to-many class="NHibernateTest.Grantor, NHibernateTest"/>
</bag>
<bag name="Grantees" table="OPR_Parties" where="Name_Type = 'E'" cascade="none" fetch="subselect" lazy="false" inverse="true">
<key column="Instrument_Number"/>
<one-to-many class="NHibernateTest.Grantee, NHibernateTest"/>
<filter name="E only" condition="Name_Type = 'E'"/>
</bag>
</class>
<class name ="NHibernateTest.Grantor, NHibernateTest" table="OPR_Parties" where="Name_Type = 'R'">
<id name="Id" column="Instrument_Number" access="nosetter.camelcase" unsaved-value="0">
<generator class="assigned"/>
</id>
<property name ="StreetAddress" column="Address1"/>
<property name="FirstName" column="FirstName"/>
<property name="LastName" column="LastName"/>
<property name="UnparsedName" column="Combined_Name"/>
<property name="NonPersonEntityIndicator" column="PC_Flag"/>
</class>
<class name ="NHibernateTest.Grantee, NHibernateTest" table="OPR_Parties" where="Name_Type = 'E'">
<id name="Id" column="Instrument_Number" access="nosetter.camelcase" unsaved-value="0">
<generator class="identity"/>
</id>
<property name ="StreetAddress" column="Address1"/>
<property name="FirstName" column="FirstName"/>
<property name="LastName" column="LastName"/>
<property name="UnparsedName" column="Combined_Name"/>
<property name="NonPersonEntityIndicator" column="PC_Flag"/>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
ISession session = null;
//returns open session
session = Program.NHSession;
IQuery query = session.CreateQuery("FROM PropertyRecord");
IList<PropertyRecord> records = query.List<PropertyRecord>();
session.Close();


Full stack trace of any exception that occurs: NO EXCEPTIONS

Name and version of the database you are using: SQL Server 2005

The generated SQL (show_sql=true):
SELECT grantors0_.Instrument_Number as Instrument1___1_, grantors0_.Instrument_Number as Instrument1_1_, grantors0_.Instrument_Number as Instrument1_1_0_,
grantors0_.Address1 as Address2_1_0_, grantors0_.FirstName as FirstName1_0_, grantors0_.LastName as LastName1_0_, grantors0_.Combined_Name as
Combined5_1_0_, grantors0_.PC_Flag as PC6_1_0_ FROM OPR_Parties grantors0_ WHERE grantors0_.Name_Type = 'R' and grantors0_.Instrument_Number in (select
propertyre0_.INSTRUMENT_NUMBER from OPR_Logi_Documents propertyre0_ where propertyre0_.LastUpdated_Date >= '5/17/2007') ORDER BY grantors0_.FirstName


I have a parent-child relation. The parent is the PropertyRecord and the children are the Grantees and Grantors. When I run this program I get back the correct number of children for each parent; however, each time I get a record that has multiple Grantors or Grantees the records are the same. For example if I have a PropertyRecord with 1 Grantee and 2 Grantors, both of the Grantors are the exact same record. I have searched around and tried a few things but so far no luck. Also I am not sure why the sql code is selecting the Instrument_Number multiple times, but this is not a high priority.

Thank you so much


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

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.