in the child mapping change this

CHILD:


        <property name="RegUserId" column="RegUserId" type="Int64"
insert="false" update="false" />

You have duplicate mapped once explicit see above and once implicit
see below

<many-to-one name="RegUsers" column="RegUserId" not-
null="true" class="PaRegUser, App_Code" />

Greetings

On 29 jul, 15:05, Teclioness <[email protected]> wrote:
> Hi,
>
> I have a parent child relationship tables set up. In the UI, I show
> the details of parent and child details. After the user make changes
> in UI, I need to save it back to the db, but I am getting following
> error:
>
> NHibernate.ADOException was caught
>   Message="could not update: [PlanningMaps.vo.PaRegAddresses#2][SQL:
> UPDATE PaRegAddresses SET RegUserId = ?, AddressCity = ?,
> AddressCountry = ?, AddressLine = ?, AddressLine1 = ?, AddressPostcode
> = ?, RegUserId = ?, IsBillingAddress = ?, IsShippingAddress = ? WHERE
> RegAddressID = ?]"
>
> and innerexception is:
>
> System.Data.SqlClient.SqlException: Column name 'RegUserId' appears
> more than once in the result column list.
>
> Here is the mapping details:
> PARENT:
>
> <?xml version="1.0" encoding="utf-8" ?>
>    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> namespace="PlanningMaps.vo" assembly="PlanningMaps.vo">
>     <class name="PaRegUser, __code" table="PaRegUsers" lazy="false">
>         <id name="Id" type="Int64" column="RegUserId">
>                 <generator class="identity" />
>         </id>
>         <property name="RegTradeName" column="RegTradeName"
> type="String" />
>         <property name="RegTitle" column="RegTitle" type="String" />
>         <property name="RegContactName" column="RegContactName"
> type="String" />
>         <property name="RegPassword" column="RegPassword"
> type="String" />
>         <property name="RegEmail" column="RegEmail" type="String" />
>         <property name="RegPhoneNumber" column="RegPhoneNumber"
> type="String" />
>         <bag name="PaRegAddresses" inverse="true" cascade="all-delete-
> orphan" lazy="false">
>                 <key column="RegUserID" />
>                 <one-to-many class="PaRegAddresses, App_Code" />
>         </bag>
>     </class>
> </hibernate-mapping>
>
> CHILD:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> namespace="PlanningMaps.vo" assembly="PlanningMaps.vo">
>     <class name="PaRegAddresses, __code" table="PaRegAddresses"
> lazy="false">
>         <id name="Id" type="Int64" column="RegAddressID">
>                 <generator class="identity" />
>         </id>
>         <property name="RegUserId" column="RegUserId" type="Int64" />
>         <property name="AddressCity" column="AddressCity"
> type="String" />
>         <property name="AddressCountry" column="AddressCountry"
> type="String" />
>         <property name="AddressLine" column="AddressLine"
> type="String" />
>         <property name="AddressLine1" column="AddressLine1"
> type="String" />
>         <property name="AddressPostcode" column="AddressPostcode"
> type="String" />
>         <many-to-one name="RegUsers" column="RegUserId" not-
> null="true" class="PaRegUser, App_Code" />
>         <property name="IsBillingAddress" column="IsBillingAddress"
> type="Boolean" />
>         <property name="IsShippingAddress" column="IsShippingAddress"
> type="Boolean" />
>     </class>
> </hibernate-mapping>
>
> AND THE CODE:
>
> public void UpdateRegCustomer( PaRegUser regUser ) { ITransaction tx =
> null; try { if (!session.IsConnected) { session.Reconnect(); }
>
>         tx = session.BeginTransaction();
>
>         if (regUser != null)
>             session.Update(regUser);
>             tx.Commit();
>             }
>         session.Disconnect();
>         }
>     catch (Exception ex)
>         {
>         tx.Rollback();
>         session.Disconnect();
>         log.Error("UpdateRegCustomer( PaRegUser regUser ) method",
> ex);
>         throw ex;
>         // handle exception
>         }
>     }
> Pl. let me know what it is I am doing wrong here. and what change I
> need to do to be able to update parent and child records. Thank you
> for your help.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to