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: Merge DomainObject mapped from DTO into empty Session
PostPosted: Fri Oct 17, 2008 4:23 pm 
Newbie

Joined: Fri Oct 17, 2008 3:16 pm
Posts: 1
Scenario: Silverlight -> WCF -> NHibernate

  1. client requests a DTO from the server
  2. a corresponding DomainObject is retrieved via NHibernate
  3. a mapping layer translates the DomainObject to a DTO
  4. DTO is returned to the client
  5. client updates DTO and sends to server for update
  6. server maps DTO to new DomainObject
  7. Session.Merge(DomainObject) is called on empty ISession


This situation works perfectly when the following mapping file doesn't contain the "Components" bag, including correct collection removals, updates, etc. However, when a second bag is added ie: "Components", all items in all collections are removed (see gen'd sql). What gives?

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="test" namespace="test">
  <class name="Recipe">
    <id name="ObjectId">
      <generator class="native">
        <param name="sequence">recipeSeq</param>
      </generator>
    </id>
    <version name="Version" type="Int64" generated="never" unsaved-value="0"/>
    <property name="Name"/>
    <bag name="PreparationSteps" table="preparationStep" inverse="true" cascade="all-delete-orphan">
      <key column="recipeId"/>
      <one-to-many class="PreparationStep"/>
    </bag>
    <bag name="Components" table="recipeComponent" inverse="true" cascade="all-delete-orphan">
      <key column="recipeId"/>
      <one-to-many class="RecipeComponent"/>
    </bag>
  </class>
</hibernate-mapping>


The generated SQL (show_sql=true):
Code:
NHibernate: UPDATE Recipe SET Version = :p0, Name = :p1 WHERE ObjectId = :p2 AND Version = :p3; :p0 = '2', :p1 = 'Recipe 2139412171', :p2 = '892', :p3 = '1'
[color=red]NHibernate: DELETE FROM PreparationStep WHERE ObjectId = :p0 AND Version = :p1; :p0 = '1120', :p1 = '1'
NHibernate: DELETE FROM PreparationStep WHERE ObjectId = :p0 AND Version = :p1; :p0 = '1121', :p1 = '1'
NHibernate: DELETE FROM RecipeComponent WHERE ObjectId = :p0 AND Version = :p1; :p0 = '548', :p1 = '1'
NHibernate: DELETE FROM RecipeComponent WHERE ObjectId = :p0 AND Version = :p1; :p0 = '547', :p1 = '1'[/color]


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.