views:

796

answers:

1

I have a situation where I have two entities that share a primary key (Transaction and TransactionDetail). I have them mapped using many-to-one relationship from Transaction to TransactionDetail and from TransactionDetail to Transaction. Transaction detail holds one record for each transaction.

However, when I create a new transaction detail object and add it to the transaction, NHibernate tries to update the Transaction table with a query like 'update transaction set id = ? where id = ?' with the same value for each parameter.

Since the mapping is on the primary key column, I don't want the transaction to be updated. In fact, since the primary key is an identity column, I get an error when it tries to update the value. How can I prevent NHibernate from updating the Transaction table when a new TransactionDetail record is created?

+2  A: 

You may want to look into the one-to-one or join-table types of mappings. many-to-one means something specific, and it looks like your case might better fit the profile of one of the other two types of mappings.

Justice
Thanks Justice,I had tried the one-to-one mapping and that wasn't working for me, but the join table mapping looks like it might just be the ticket.
SteveBering

related questions