-->
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: collection of components and persitency
PostPosted: Mon Jan 28, 2008 11:27 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello again.

One more simple question (I guess): how does nhibernate decides if a collection of components should be mapped to a table? for instance, suppose the following example:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
schema="dbo"
assembly="SRA.Mercados.Facturacao"
namespace="SRA.Mercados.Facturacao">
<class name="ItemFactura"
table="ItemFactura" lazy="false">
<id name="Id" column="IdItemFactura" unsaved-value="0">
<generator class="identity" />
</id>
<version name="Version" column="Version"
type="int"/>
<property name="Desconto" column="Descontos" />
<bag name="_entradasAssociadas" table="OrigemEntradaFactura"
cascade="all"
access="field" lazy="false">
<key column="IdItemFactura" />
<composite-element class="OrigemEntradaFactura">
<property name="IdGuia" column="IdGuia" />
<property name="IdLote" column="IdLote" />
<property name="IdProduto" column="IdProduto" />
<property name="Preco" column="Preco" />
<property name="Quantidade" column="Quantidade" />
<property name="NifVendedor" column="NIFVendedor" />
<property name="NifComprador" column="NIFComprador" />
<property name="Guid" column="Guid" />
</composite-element>
</bag>
</class>
</hibernate-mapping>

saving an entity of type ItemFactura is not beeing cascaded to the OrigemEntradaFactura table. Is there anything wrong with this code?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 12:45 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Maybe your composite object wasn't changed in memory and Hibernate was smart enough to realize a post to the database wasn't necessary?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 2:44 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello.
well, that is what I'm thinking but the thing is that we're talking about an insert. if it's an insert operation, how can the component collection already be persisted on the database?

My understanding of a collection of components is that NH would automatically persist those elements when its "parent" element gets persisted. It looks like I'm wrong. can anyone give me any tips on this?

thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 3:39 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
How about this: OrigemEntrada existed previously from some other ItemFactura, and Hibernate just reused it?

The main question here is: does the OrigemEntrada ends being reflected correctly in your database?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 3:42 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello again.

well, that is what I'm trying to say: all the tables are empty and all the objects were created for the 1st time. that's why I'm having some trouble understanding how NH works in this scenarios...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 3:52 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
hello again...


damn, I think I've seen what's wrong: WCF serialization. if I use the same code without going through SCF, everything works out correctly...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 5:22 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Solved it with this cool post:

http://lunaverse.wordpress.com/2007/05/ ... hibernate/


Top
 Profile  
 
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.