-->
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.  [ 7 posts ] 
Author Message
 Post subject: composite-element / many-to-one problem
PostPosted: Fri Sep 16, 2005 4:42 am 
Good day!

I've implemented the following mapping

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Company" table="COMPANY">

    <!-- ... -->

    <set name="Addresses" cascade="all" table="COMPANY_ADDRESS">
      <key column="COMPANY_ID"/>
      <composite-element class="Address">

        <!-- Doesn't seem to work -->
        <many-to-one name="State" column="STATE_ID"/>

        <property name="City" column="CITY"/>
        <property name="Street1" column="STREET"/>
        <property name="Zip" column="ZIP"/>
       </composite-element>
    </set>
 
    <!-- ... -->

  </class>
</hibernate-mapping>

(Source: http://www.hibernate.org/hib_docs/v3/reference/en/html/components.html#components-incollections)

Implementation of State class is trivial. Data model relations are fine (all required foreign/primary keys are present).

But that mapping doesn't seem to work. I know that problem in <many-to-one> element inside <composite-element> (it works fine without it). I though that NHibernate supports such those elements nested that way. What will you suggest?

Any help will be surely appreciated.


Top
  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 5:13 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What exactly does not work?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 10:44 am 
sergey wrote:
What exactly does not work?


Sorry :oops: . I got over the last error so let me proceed with the next one appeared.

The extraction of Company object seems to work fine. Addresses are extracted normaly as well.

After that I alter one of the addresses by altering the State property.

When I call ISession.SaveOrUpdate(Company) I expect that altered address will be updated in COMPANY_ADDRESS table. Instead NHibernate just creates copy of that address with altered State property, no updation occurs.

Any ideas?


Top
  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 1:20 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You probably didn't override Equals and GetHashCode for Address.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 3:06 am 
sergey wrote:
You probably didn't override Equals and GetHashCode for Address.


Thanks, but that is not the case, I guess. I've overriden those methods but it didn't helped.

It worked fine without Equals() and GetHashCode() when the State was stored/mapped as plain string.


Top
  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 3:40 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Ok, please show the mappings for your classes and the code that is causing the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 4:11 am 
Before I do so... I've noticed that insertion occurs only if there are some fields with null values, e.g no State was specified before I edit the address. If all the fiedls have not null values before edit then the sequential update occurs normaly.

Why does NHibernate treats null-fields in <set> so specificly?

P.S. Thanks for your support though I'm such a dummy in ORM.


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