Thanks, this is exacty what I have done.
However, my point is that when executing the code:
var orderRepo = new OrderRepository();
var order = orderRepo.GetById(new
Guid("912e9e25-2e51-4371-8b84-8a8d81d0e305"));
Transaction tx = new Transaction();
tx.ExecutedOn = DateTime.Now;
tx.Success = true;
order.AddTransaction(tx);
orderRepo.Update(order);
The following SQL is generated (viewing in NHProf):
select ... from Orders where Id = blah
select .. from Transactions where OrderId = blah (lazy = false)
Both these lines are expected
Then:
insert into Transactions (add the new transaction)
update transaction (issued for every transaction belonging to order)
It is this last part that does not make sense. I am told that adding a
new transaction in this way should only insert the new transaction
when I perform an update on the order entity. However, in addition to
this it generates an update for every existing transaction belonging
to the order (setting the values to exactly what they were before).
On Apr 15, 9:10 pm, Gianluca Gravina <[email protected]>
wrote:
> As cliff said, one to many relations should be implemented as
> bidirectional, so, transaction class should have a reference to Order
> class, in the addtransaction method add the bidirectional links whit
> tx.order = this, if the mapping of transaction is well defined it
> should make the trick,
>
> gianluca
>
>
>
>
>
> On Thursday, April 15, 2010, cliff vaughn <[email protected]> wrote:
> > based on your mapping, 'inverse=true' would prevent the order from having
> > responsibility to save the transaction. in the AddTransaction method, you
> > would need to do "tx.Order = this;
>
> > On Thu, Apr 15, 2010 at 8:12 AM, ben <[email protected]> wrote:
>
> > I have recently started learning NHibernate and am struggling to find
> > documentation on how to handle updates in a set.
>
> > For example, I have an order object with a one to many relationship to
> > transaction. My transaction table has a foreign key OrderId. The xml
> > for my mapping is:
>
> > <set name="Transactions" table="Transactions" inverse="true"
> > lazy="false">
> > <key column="OrderId"/>
> > <one-to-many class="Transaction"/>
> > </set>
>
> > What I would like to do is to add transactions like so:
>
> > Order order = repo.GetById(id);
> > Transaction tx = new Transaction();
> > order.AddTransaction(tx);
> > repo.Update(order);
>
> > When I issue ISession.Update I would expect that any new transactions
> > added to the Order object are saved to the database (via an insert
> > command).
>
> > In order to achieve this I set the cascade attribute for the above
> > set.
>
> > However, in addition to adding any new transactions an update command
> > is issued for every existing transaction (I have checked in NHProf and
> > an update command is generated for each transaction setting all
> > columns to the original values).
>
> > Have anyone got an example (or perhaps a link) to an example that
> > demonstrates how this should work?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/nhusers?hl=en.
>
> > --
> > thanks
>
> > cliff
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/nhusers?hl=en.
>
> --
> Gianluca Gravinahttp://blogs.ugidotnet.org/thinkingingrava- Hide quoted text -
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.