-->
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.  [ 2 posts ] 
Author Message
 Post subject: Double generation of field name on save
PostPosted: Fri Jul 22, 2005 3:29 am 
Newbie

Joined: Sun May 15, 2005 11:39 pm
Posts: 17
Location: Australia
Hello - I'm stuck in a big way and am wondering if someone can help me.

I have a clsOrder object which relats many-to-one with a clsCustomer object.

When I make changes to the clsOrder object, save it and then flush the session, I get an
Quote:
'iCustID_' appears more than once in the result column list' error.


I can't for the life of me figure out what's going on... and don't even know how to bypass NH doing the save so that I can do it manually.

Any help with this would be greatly appreciated as I'm now well and truly committed to using NH in my app - there's no going back.


Thanks very much in advance, There's another objects that touches the clsOrder class... (I've included clsItem's map). If it's not obvious what's going on, I'll try and dig out the other classes hbm files.

Cheers,


Damien Sawyer

Quote:
The Error
-------------------
2005-07-22 17:09:42,869 [3076] ERROR NHibernate.ADOException [] <> - could not synchronize database state with session
Exception: System.Data.SqlClient.SqlException
Message: Column name 'iCustID_' appears more than once in the result column list.
Source: .Net SqlClient Data Provider
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()



----------------------
Violating SQL String generated by NH


Code:
exec sp_executesql N'UPDATE tblOrders SET cLITM = @p0, iQtyCommit = @p1, iCustID_ = @p2, dRequestDate = @p3, cDataTypeID = @p4, cCustOrderNo = @p5, dPickDate = @p6, cMCU = @p7, iCustID_ = @p8, cCommitStatus = @p9, iQtyOrdered = @p10, nLNID = @p11, nDOCO = @p12, cMCUExt = @p13 WHERE iOrderID = @p14', N'@p0 nvarchar(4000),@p1 int,@p2 int,@p3 datetime,@p4 nvarchar(4000),@p5 nvarchar(4000),@p6 datetime,@p7 nvarchar(4000),@p8 int,@p9 nvarchar(4000),@p10 int,@p11 int,@p12 int,@p13 nvarchar(4000),@p14 int', @p0 = N'738522', @p1 = 240, @p2 = 145, @p3 = 'Jul 22 2005 12:00:00:000AM', @p4 = N'SO        ', @p5 = N'94623878', @p6 = 'Jul 22 2005 12:00:00:000AM', @p7 = N'WES', @p8 = 145, @p9 = N'n', @p10 = 240, @p11 = 1, @p12 = 542511, @p13 = N'WES', @p14 = 3218





clsOrder.hbm.xml
------------------

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="OPWLibrary.clsOrder, OPWLibrary" table="tblOrders">
      <id name="OrderID" column="iOrderID" unsaved-value="0">
         <generator class="identity" />
      </id>
            
      <property name="DataTypeID" column="cDataTypeID"/>
      <property name="CustID" column="iCustID_"/>
      <property name="CustOrderNumber" column="cCustOrderNo"/>
      <property name="QtyOrdered" column="iQtyOrdered"/>
      <property name="QtyCommitted" column="iQtyCommit"/>
      <property name="CommitStatus" column="cCommitStatus"/>
      <property name="RequestDate" column="dRequestDate"/>
      <property name="PickDate" column="dPickDate"/>
      <property name="DOCO" column="nDOCO"/>
      <property name="LNID" column="nLNID"/>
      <property name="_mCU"  access="field"  column="cMCU"/>
      <property name="_mCUext"  access="field"  column="cMCUExt"/>
      
      <!--<many-to-one name="Mcu"  access="field" column="cMCU" not-null="true"/>-->
      <!--<many-to-one name="McuExtended"  access="field" column="cMCUExt" not-null="true" />-->
      <many-to-one name="Item"  access="field" column="cLITM" not-null="true"/>
      <many-to-one name="Customer"  access="field" column="iCustID_" not-null="true"/>
      
      
   </class>
</hibernate-mapping>




clsCustomer.hbm.xml
----------------------
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="OPWLibrary.clsCustomer, OPWLibrary" table="tblCustomers">
      <id name="_custID" access="field" column="iCustID" unsaved-value="0">
         <generator class="identity" />
      </id>
            
      <property name="_addressBookCode" access="field" column="nAddressBookCode"/>
      <property name="_majorCode" access="field" column="cMajorCode"/>
      <property name="_name" access="field" column="cName"/>
      <property name="_berriSite" access="field" column="bBerriSite"/>
            
   <bag   name="_orders_NH" access="field" inverse="true" lazy="true">
      <key column="iCustID"/>
      <one-to-many class="OPWLibrary.clsOrder,OPWLibrary"/>
   </bag>
      
   <bag name="_dCs_NH" access="field" table ="tblCustomer_DC_Join" lazy="true">
      <key column="iCustID"/>
      <many-to-many class ="OPWLibrary.clsDC, OPWLibrary" column="iDCID"/>
   </bag>
   
   
      
   </class>
</hibernate-mapping>


clsItem.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="OPWLibrary.clsItem, OPWLibrary" table="tblItems">
      <id name="Litm" column="cLITM" unsaved-value="0" length="6" type="string">
         <generator class="assigned" />
      </id>
            
      <property name="Description" column="cDescription"/>
      <property name="Chilled" column="bChilled"/>
      <property name="ShelfLifeDays" column="iShelfLifeDays"/>
            
   
   <bag   name="_ordersNH" access="field" inverse="true" lazy="true">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.clsOrder,OPWLibrary"/>
   </bag>
   
   
   <set   name="_sOHs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='SOH'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_SOH,OPWLibrary"/>
   </set>
   
   <set   name="_sOHHs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='SOHH'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_SOHH,OPWLibrary"/>
   </set>
   
   <set   name="_pOs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='PO'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_PO,OPWLibrary"/>
   </set>
   
   <set   name="_wOs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='WO'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_WO,OPWLibrary"/>
   </set>
   
   <set   name="_wPs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='WP'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_WP,OPWLibrary"/>
   </set>
   
   <set   name="_sSTLs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='SSTL'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_SSTL,OPWLibrary"/>
   </set>

   <set   name="_fCSTs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='FCST'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_FCST,OPWLibrary"/>
   </set>
   
   <set   name="_sOs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='SO'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_SO,OPWLibrary"/>
   </set>
   
   <set   name="_sTs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='ST'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_ST,OPWLibrary"/>
   </set>

   <set   name="_sXs_NH" access="field" inverse="true" lazy="true" where="cDataTypeID='SX'">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_SX,OPWLibrary"/>
   </set>
   
   <set   name="_gENERICs_NH" access="field" inverse="true" lazy="true">
      <key column="cLITM"/>
      <one-to-many class="OPWLibrary.CDT.clsCDT_Generic,OPWLibrary"/>
   </set>

<!--   <bag name="_branchesNH" access="field" inverse="true" table ="tblCoreData" lazy="true">
      <key column="cLITM"/>
      <many-to-many class ="OPWLibrary.clsBranch, OPWLibrary" column="cMCU"/>
   </bag>
-->

   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 7:20 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
Don't waste your time analyzing the sql generated by NHibernate! All you have to check are your mappings.

In clsOrder.hbm.xml you have both a property CustID on the iCustID column and a many to one mapping to the customer object on the same iCustID column! So when NHibernates tries to save them, of course will do it twice!

At any rate holding in your Order object the CustID value is useless and bad practice. This should remain an internal detail, managed by NHibernate and not by your code. Your Order code should deal only with Customer objects. If you really need the customer ID, keep it as a property of the Customer and not of the Order.

Hope this helps,
Radu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.