java - Hibernate insert query -


during insertion in hibernate query i'm passing fields table class objects i've mapped corresponding tables, query works fine query becoming large because each of these mapped objects getting updated individually corresponding tables.

can please tell me whether correct way of insertion , why i'm getting update queries.

hibernate: insert ortms.tool_modified_his_tbl (tool_desc, old_tool_desc, connec1, old_connec1, connec2, old_connec2, landed_cost, old_landed_cost, acqui_date, old_acqui_date, manuf_date, old_manuf_date, price_ref, old_price_ref, op_rate_cost, old_op_rate_cost, stb_rate_cost, old_stb_rate_cost, day_rate1_cost, old_day_rate1_cost, day_rate2_cost, old_day_rate2_cost, packermilling_cost, old_packermilling_cost, sale_value, old_sale_value, status, created_date, modified_date, tool_id, tool_modi_reas_id, tool_modi_usr_id, supplier_id, old_supplier_id, tc_status_id, old_tc_status_id, pricing_type_id, old_pricing_type_id, old_ownership_id, ownership_id, unit_id, old_unit_id, branch_id, old_branch_id, reta_tool_choice_id, old_reta_tool_choice_id, non_ser_tol_cho_id, old_non_ser_tol_cho_id, charge_by_id, old_charge_by_id, size_range_id, old_size_range_id, rack_id, old_rack_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) hibernate: update ortms.master2_tool_master set tool_id=?, tool_desc=?, connec1=?, connec2=?, landed_cost=?, acqui_date=?, manuf_date=?, price_ref=?, op_rate_cost=?, stb_rate_cost=?, day_rate1_cost=?, day_rate2_cost=?, packermilling_cost=?, sale_value=?, uploaded_filename=?, uploaded_file=?, status=?, created_date=?, modified_date=?, supplier_id=?, tc_status_id=?, pricing_type_id=?, unit_id=?, reta_tool_choice_id=?, non_ser_tol_cho_id=?, branch_id=?, charge_by_id=?, size_range_id=?, rack_id=?, ownership_id=? id=? hibernate: update ortms.table_users set user_code=?, username=?, password=?, first_name=?, last_name=?, status=?, created_date=?, modified_date=?, dept_id=?, branch_id=? id=? hibernate: update ortms.table_choice_select set choice_name=?, status=?, created_date=?, modified_date=? id=? hibernate: update ortms.master2_toolmast_chargeby set chargeby=?, status=?, created_date=?, modified_date=? id=? hibernate: update ortms.master2_sizerange set size_code=?, size_range=?, status=?, created_date=?, modified_date=?, grp_lev3_id=? id=? hibernate: update ortms.master2_group_level3 set grp_lev3_name=?, grp_lev3_desc=?, created_date=?, modified_date=?, status=?, grp_lev2_id=? id=? hibernate: update ortms.master2_group_level2 set grp_lev2_name=?, grp_lev2_desc=?, created_date=?, modified_date=?, status=?, grp_lev1_id=? id=? after calling action: master2.toolmaster.toolmaster time taken: 1234 ms 

updation 2

toolmodifiedhistbl.hbm.xml

<?xml version="1.0"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- generated mar 2, 2013 9:29:05 pm hibernate tools 3.2.1.ga --> <hibernate-mapping>     <class name="mappingfiles.toolmodifiedhistbl" table="tool_modified_his_tbl" catalog="ortms">         <id name="id" type="java.lang.integer">             <column name="id" />             <generator class="identity" />         </id>           <property name="tooldesc" type="string">             <column name="tool_desc" length="65535" />         </property>         <property name="oldtooldesc" type="string">             <column name="old_tool_desc" length="65535" />         </property>         <property name="connec1" type="string">             <column name="connec1" length="60" />         </property>         <property name="oldconnec1" type="string">             <column name="old_connec1" length="60" />         </property>         <property name="connec2" type="string">             <column name="connec2" length="60" />         </property>         <property name="oldconnec2" type="string">             <column name="old_connec2" length="60" />         </property>           <property name="landedcost" type="string">             <column name="landed_cost" length="20" />         </property>         <property name="oldlandedcost" type="string">             <column name="old_landed_cost" length="20" />         </property>         <property name="acquidate" type="date">             <column name="acqui_date" length="10" />         </property>         <property name="oldacquidate" type="date">             <column name="old_acqui_date" length="10" />         </property>         <property name="manufdate" type="date">             <column name="manuf_date" length="10" />         </property>         <property name="oldmanufdate" type="date">             <column name="old_manuf_date" length="10" />         </property>           <property name="priceref" type="string">             <column name="price_ref" length="20" />         </property>         <property name="oldpriceref" type="string">             <column name="old_price_ref" length="20" />         </property>         <property name="opratecost" type="string">             <column name="op_rate_cost" length="20" />         </property>         <property name="oldopratecost" type="string">             <column name="old_op_rate_cost" length="20" />         </property>         <property name="stbratecost" type="string">             <column name="stb_rate_cost" length="20" />         </property>         <property name="oldstbratecost" type="string">             <column name="old_stb_rate_cost" length="20" />         </property>         <property name="dayrate1cost" type="string">             <column name="day_rate1_cost" length="20" />         </property>         <property name="olddayrate1cost" type="string">             <column name="old_day_rate1_cost" length="20" />         </property>         <property name="dayrate2cost" type="string">             <column name="day_rate2_cost" length="20" />         </property>         <property name="olddayrate2cost" type="string">             <column name="old_day_rate2_cost" length="20" />         </property>         <property name="packermillingcost" type="string">             <column name="packermilling_cost" length="20" />         </property>         <property name="oldpackermillingcost" type="string">             <column name="old_packermilling_cost" length="20" />         </property>         <property name="salevalue" type="string">             <column name="sale_value" length="20" />         </property>         <property name="oldsalevalue" type="string">             <column name="old_sale_value" length="20" />         </property>          <property name="status" type="string">             <column name="status" length="20" />         </property>         <property name="createddate" type="timestamp">             <column name="created_date" length="19" />         </property>         <property name="modifieddate" type="timestamp">              <column name="modified_date" length="19" />         </property>               <many-to-one class="mappingfiles.master2toolmaster" unique="true" name="toolid" column="tool_id" cascade="all" />         <many-to-one class="mappingfiles.tablemodifiedreason" unique="true" name="toolmodireasid" column="tool_modi_reas_id" cascade="all" />          <many-to-one class="mappingfiles.tableusers" unique="true" name="toolmodiusrid" column="tool_modi_usr_id" cascade="all" />           <many-to-one class="mappingfiles.tablesupplier" unique="true" name="supplierid" column="supplier_id" cascade="all" />         <many-to-one class="mappingfiles.tablesupplier" unique="true" name="oldsupplierid" column="old_supplier_id" cascade="all" />           <many-to-one class="mappingfiles.tabletoolcontractstatus" unique="true" name="tcstatusid" column="tc_status_id" cascade="all" />         <many-to-one class="mappingfiles.tabletoolcontractstatus" unique="true" name="oldtcstatusid" column="old_tc_status_id" cascade="all" />           <many-to-one class="mappingfiles.master2pricetype" unique="true" name="pricingtypeid" column="pricing_type_id" cascade="all" />         <many-to-one class="mappingfiles.master2pricetype" unique="true" name="oldpricingtypeid" column="old_pricing_type_id" cascade="all" />           <many-to-one class="mappingfiles.tableownership" unique="true" name="oldownershipid" column="old_ownership_id" cascade="all" />         <many-to-one class="mappingfiles.tableownership" unique="true" name="ownershipid" column="ownership_id" cascade="all" />           <many-to-one class="mappingfiles.master2unitmaster" unique="true" name="unitid" column="unit_id" cascade="all" />         <many-to-one class="mappingfiles.master2unitmaster" unique="true" name="oldunitid" column="old_unit_id" cascade="all" />           <many-to-one class="mappingfiles.tablebranchescompany" unique="true" name="branchid" column="branch_id" cascade="all" />         <many-to-one class="mappingfiles.tablebranchescompany" unique="true" name="oldbranchid" column="old_branch_id" cascade="all" />           <many-to-one class="mappingfiles.tablechoiceselect" unique="true" name="retatoolchoiceid" column="reta_tool_choice_id" cascade="all" />         <many-to-one class="mappingfiles.tablechoiceselect" unique="true" name="oldretatoolchoiceid" column="old_reta_tool_choice_id" cascade="all" />           <many-to-one class="mappingfiles.tablechoiceselect" unique="true" name="nonsertolchoid" column="non_ser_tol_cho_id" cascade="all" />         <many-to-one class="mappingfiles.tablechoiceselect" unique="true" name="oldnonsertolchoid" column="old_non_ser_tol_cho_id" cascade="all" />           <many-to-one class="mappingfiles.master2toolmastchargeby" unique="true" name="chargebyid" column="charge_by_id" cascade="all" />         <many-to-one class="mappingfiles.master2toolmastchargeby" unique="true" name="oldchargebyid" column="old_charge_by_id" cascade="all" />           <many-to-one class="mappingfiles.master2sizerange" unique="true" name="sizerangeid" column="size_range_id" cascade="all" />         <many-to-one class="mappingfiles.master2sizerange" unique="true" name="oldsizerangeid" column="old_size_range_id" cascade="all" />           <many-to-one class="mappingfiles.master2racks" unique="true" name="rackid" column="rack_id" cascade="all" />         <many-to-one class="mappingfiles.master2racks" unique="true" name="oldrackid" column="old_rack_id" cascade="all" />       </class> </hibernate-mapping> 

tableusers.hbm.xml

<?xml version="1.0"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- generated jan 13, 2013 4:26:04 pm hibernate tools 3.2.1.ga --> <hibernate-mapping>     <class name="mappingfiles.tableusers" table="table_users" catalog="ortms">         <id name="id" type="java.lang.integer">             <column name="id" />             <generator class="identity" />         </id>         <property name="usercode" type="string">             <column name="user_code" length="60" />         </property>          <property name="username" type="string">             <column name="username" length="50" />         </property>          <property name="password" type="string">             <column name="password" length="50" />         </property>         <property name="firstname" type="string">             <column name="first_name" length="60" />         </property>         <property name="lastname" type="string">             <column name="last_name" length="60" />         </property>         <property name="status" type="string">             <column name="status" length="20" />         </property>         <property name="createddate" type="timestamp">             <column name="created_date" length="19" />         </property>         <property name="modifieddate" type="timestamp">             <column name="modified_date" length="19" />         </property>             <many-to-one class="mappingfiles.tabledepartments" unique="true" name="deptid" column="dept_id" cascade="all" />         <many-to-one class="mappingfiles.tablebranchescompany" unique="true" name="branchid" column="branch_id" cascade="all" />     </class> </hibernate-mapping> 

updation 3

i've removed cascade="all" attribute mappings....now i'm getting 1 update rest clear

hibernate: insert ortms.tool_modified_his_tbl (tool_desc, old_tool_desc, connec1, old_connec1, connec2, old_connec2, landed_cost, old_landed_cost, acqui_date, old_acqui_date, manuf_date, old_manuf_date, price_ref, old_price_ref, op_rate_cost, old_op_rate_cost, stb_rate_cost, old_stb_rate_cost, day_rate1_cost, old_day_rate1_cost, day_rate2_cost, old_day_rate2_cost, packermilling_cost, old_packermilling_cost, sale_value, old_sale_value, status, created_date, modified_date, tool_id, tool_modi_reas_id, tool_modi_usr_id, supplier_id, old_supplier_id, tc_status_id, old_tc_status_id, pricing_type_id, old_pricing_type_id, old_ownership_id, ownership_id, unit_id, old_unit_id, branch_id, old_branch_id, reta_tool_choice_id, old_reta_tool_choice_id, non_ser_tol_cho_id, old_non_ser_tol_cho_id, charge_by_id, old_charge_by_id, size_range_id, old_size_range_id, rack_id, old_rack_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) hibernate: update ortms.master2_tool_master set tool_id=?, tool_desc=?, connec1=?, connec2=?, landed_cost=?, acqui_date=?, manuf_date=?, price_ref=?, op_rate_cost=?, stb_rate_cost=?, day_rate1_cost=?, day_rate2_cost=?, packermilling_cost=?, sale_value=?, uploaded_filename=?, uploaded_file=?, status=?, created_date=?, modified_date=?, supplier_id=?, tc_status_id=?, pricing_type_id=?, unit_id=?, reta_tool_choice_id=?, non_ser_tol_cho_id=?, branch_id=?, charge_by_id=?, size_range_id=?, rack_id=?, ownership_id=? id=? 

the unwanted updates come "cascade all" settings. may want configure according needs. example, have here: http://www.mkyong.com/hibernate/hibernate-cascade-example-save-update-delete-and-delete-orphan/


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -