-->
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.  [ 4 posts ] 
Author Message
 Post subject: Composite-id problem
PostPosted: Wed May 16, 2007 11:45 am 
Newbie

Joined: Wed May 16, 2007 11:41 am
Posts: 8
I have a legacy table which is composed out three key fields. It is
representing a bank. I'm using NHibernate in my ASP.NET application to
glue everything together. I'm already searching for an answer the last
couple of weeks, but to no aval.

Hibernate Version: v1.1.4322
Database: Sql server 2000, SP4


The table layout is:
* customer id
* bank name
* bank account no
status
(the * means this is a part of the composite key)

This is my mapping:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
        <class name="Com.Hotec.Manager.Hibernate.Model.Bank,
Com.Hotec.Manager" table="bank">
                <composite-id>
                        <key-property name="BankName" column="Bank"/>
                        <key-many-to-one name="Customer"
class="Com.Hotec.Manager.Hibernate.Model.Customer, Com.Hotec.Manager"
column="CustomerId"/>
                        <key-property name="AccountNo" column="account"/>
                </composite-id>

                <many-to-one name="StatusObj" column="status" not-null="true"
class="Com.Hotec.Manager.Hibernate.Model.HotecStatus,
Com.Hotec.Manager" update="false" insert="false" />
                <property name="Active" column="status" type="System.Int16" not-
null="true"/>
        </class>
</hibernate-mapping>


The query I'm executing: "select bank from
Com.Hotec.Manager.Hibernate.Model.Bank bank left outer join
bank.Customer customer"

The error I'm getting is: {"Could not execute query" }
NHibernate.ADOException InnerException: Exception of type
System.StackOverflowException was thrown

Is there anyone that can help me with this problem? I cannot figure it
out what is wrong... Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 4:33 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Sounds like a problem with the mapped class. Can you post the code?

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 4:10 am 
Newbie

Joined: Wed May 16, 2007 11:41 am
Posts: 8
This is the mapped class Customer:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Com.Hotec.Manager.Hibernate.Model.Customer, Com.Hotec.Manager" table="Customer">
      <id name="CustomerId" type="Int32" column="id" unsaved-value="0">
         <generator class="assigned" />
      </id>
      
      <property name="CustomerCode" column="CustomerCode" type="String" length="50" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Name" column="Name" type="String" length="100" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Street" column="Street" type="String" length="100" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="PostalCode" column="PostalCode" type="String" length="50" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Municipality" column="Municipality" type="String" length="50" not-null="false">
         <meta attribute="field-description"></meta>
      </property>   
      
      <many-to-one name="ProvinceObj" column="Province" not-null="true" class="Com.Hotec.Manager.Hibernate.Model.Province, Com.Hotec.Manager" update="false" insert="false" />
      <property name="ProvinceId" column="Province" type="System.Int16" not-null="true"/>
      
      <many-to-one name="CountryObj" column="Country" not-null="true" class="Com.Hotec.Manager.Hibernate.Model.Country, Com.Hotec.Manager" update="false" insert="false" />
      <property name="CountryId" column="Country" type="System.Int16" not-null="true"/>
      
      <property name="Phone" column="Phone" type="String" length="20" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Fax" column="Fax" type="String" length="20" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Email" column="Email" type="String" length="100" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="VATNumber" column="VATNumber" type="String" length="50" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="TradeRegister" column="TradeRegister" type="String" length="50" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="REG" column="REG" type="String" length="50" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Choice" column="Choice" type="System.Char" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="ReductionStair" column="ReductionStair" type="System.Decimal" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="ReductionTreatmentStair" column="ReductionTreatmentStair" type="System.Decimal" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="ReductionDoor" column="ReductionDoor" type="System.Decimal" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="ReductionGlassDoor" column="ReductionGlassDoor" type="System.Decimal" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="ReductionTreatmentDoor" column="ReductionTreatmentDoor" type="System.Decimal" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Username" column="Username" type="String" length="100" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <property name="Password" column="Password" type="String" length="32" not-null="false">
         <meta attribute="field-description"></meta>
      </property>
      
      <many-to-one name="StatusObj" column="status" not-null="true" class="Com.Hotec.Manager.Hibernate.Model.HotecStatus, Com.Hotec.Manager" update="false" insert="false" />
      <property name="Active" column="status" type="System.Int16" not-null="true"/>   
   </class>
</hibernate-mapping>


I've tried and changed the query to a select count(*) from Com.Hotec.Manager.Hibernate.Model.Bank and that worked? Can't seem to find out why the count(*) works and a regular query doesn't. Thank you for any help!


Last edited by flokky on Mon May 21, 2007 6:17 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 6:16 am 
Newbie

Joined: Wed May 16, 2007 11:41 am
Posts: 8
I've found why the StackOverflowException occured: I made a mistake while overriden the equals and getHashCode methods.

After I actually did it like it was in the documentation, it worked perfectly.

Hopefully this will help others...


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