草庐IT

java - Hibernate 插入查询

coder 2024-03-20 原文

在 hibernate 查询中插入期间,我将一些字段作为表类对象传递,我已映射到相应的表,查询工作正常但查询变得太大,因为这些映射对象中的每一个都被单独更新到它们的相应的表格。

谁能告诉我这是否是正确的插入方式以及为什么我会收到这些更新查询。

Hibernate: insert into 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=? where id=?
Hibernate: update ortms.table_users set user_code=?, username=?, password=?, first_name=?, last_name=?, status=?, created_date=?, modified_date=?, dept_id=?, branch_id=? where id=?
Hibernate: update ortms.table_choice_select set choice_name=?, status=?, created_date=?, modified_date=? where id=?
Hibernate: update ortms.master2_toolmast_chargeby set chargeby=?, status=?, created_date=?, modified_date=? where id=?
Hibernate: update ortms.master2_sizerange set size_code=?, size_range=?, status=?, created_date=?, modified_date=?, grp_lev3_id=? where id=?
Hibernate: update ortms.master2_group_level3 set grp_lev3_name=?, grp_lev3_desc=?, created_date=?, modified_date=?, status=?, grp_lev2_id=? where id=?
Hibernate: update ortms.master2_group_level2 set grp_lev2_name=?, grp_lev2_desc=?, created_date=?, modified_date=?, status=?, grp_lev1_id=? where id=?
After calling action: master2.toolmaster.ToolMaster Time taken: 1234 ms

更新 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 by 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 by 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>

更新 3

我已经从所有映射中删除了 cascade="all" 属性....现在我得到了一个更新休息所有清除

Hibernate: insert into 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=? where id=?

最佳答案

不需要的更新来自“全部级联”设置。您可能希望根据需要正确配置它。例如,看看这里:http://www.mkyong.com/hibernate/hibernate-cascade-example-save-update-delete-and-delete-orphan/

关于java - Hibernate 插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15200940/

有关java - Hibernate 插入查询的更多相关文章

  1. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  2. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  3. ruby-on-rails - 在 Rails 和 ActiveRecord 中查询时忽略某些字段 - 2

    我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr

  4. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  5. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  6. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  7. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  8. 【Java 面试合集】HashMap中为什么引入红黑树,而不是AVL树呢 - 2

    HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候

  9. 【Java入门】使用Java实现文件夹的遍历 - 2

    遍历文件夹我们通常是使用递归进行操作,这种方式比较简单,也比较容易理解。本文为大家介绍另一种不使用递归的方式,由于没有使用递归,只用到了循环和集合,所以效率更高一些!一、使用递归遍历文件夹整体思路1、使用File封装初始目录,2、打印这个目录3、获取这个目录下所有的子文件和子目录的数组。4、遍历这个数组,取出每个File对象4-1、如果File是否是一个文件,打印4-2、否则就是一个目录,递归调用代码实现publicclassSearchFile{publicstaticvoidmain(String[]args){//初始目录Filedir=newFile("d:/Dev");Datebeg

  10. sql - 查询忽略时间戳日期的时间范围 - 2

    我正在尝试查询我的Rails数据库(Postgres)中的购买表,我想查询时间范围。例如,我想知道在所有日期的下午2点到3点之间进行了多少次购买。此表中有一个created_at列,但我不知道如何在不搜索特定日期的情况下完成此操作。我试过:Purchases.where("created_atBETWEEN?and?",Time.now-1.hour,Time.now)但这最终只会搜索今天与那些时间的日期。 最佳答案 您需要使用PostgreSQL'sdate_part/extractfunction从created_at中提取小时

随机推荐