当前位置: 首页 > news >正文

seo网站推广可以自己搞吗辽宁建设工程招投标信息网

seo网站推广可以自己搞吗,辽宁建设工程招投标信息网,谷歌seo专员是指什么意思,阿里手机网站开发框架您可能会遇到必须对关系数据库中存储的大量数据集执行批量删除的情况。 如果您将JPA与Hibernate一起用作基础OR映射器#xff0c;则可以尝试通过以下方式调用EntityManager的remove#xff08;#xff09;方法#xff1a; public void removeById(long id) {RootEntity ro… 您可能会遇到必须对关系数据库中存储的大量数据集执行批量删除的情况。 如果您将JPA与Hibernate一起用作基础OR映射器则可以尝试通过以下方式调用EntityManager的remove方法 public void removeById(long id) {RootEntity rootEntity entityManager.getReference(RootEntity.class, id);entityManager.remove(rootEntity); } 首先我们加载要删除的实体的引用表示形式然后将此引用传递给EntityManager。 假设上面的RootEntity与名为ChildEntity的类有子关系 OneToMany(mappedBy rootEntity, fetch FetchType.EAGER, cascade CascadeType.ALL) private Set childEntities new HashSet(0); 如果现在打开hibernate的属性show_sql我们将想知道发出什么SQL语句 selectrootentity0_.id as id5_1_,rootentity0_.field1 as field2_5_1_,rootentity0_.field2 as field3_5_1_,childentit1_.PARENT as PARENT5_3_,childentit1_.id as id3_,childentit1_.id as id4_0_,childentit1_.field1 as field2_4_0_,childentit1_.field2 as field3_4_0_,childentit1_.PARENT as PARENT4_0_fromROOT_ENTITY rootentity0_left outer joinCHILD_ENTITY childentit1_on rootentity0_.idchildentit1_.PARENTwhererootentity0_.id?deletefromCHILD_ENTITYwhereid?deletefromROOT_ENTITYwhereid? 为什么Hibernate首先将所有数据加载到内存中以便随后立即删除该数据 原因是JPA的生命周期要求该对象处于“托管”状态然后才能将其删除。 仅在这种状态下所有生命周期功能如拦截器才可用请参阅此处 。 因此Hibernate会在删除之前发出SELECT查询以便将RootEntity和ChildEntity都转移到“托管”状态。 但是如果我们只想删除RootEntity和ChildEntity并且知道RootEntity的ID该怎么办 答案是使用简单的DELETE查询如下面的查询。 但是由于子表的完整性约束我们首先必须删除所有依赖的子实体。 以下代码演示了如何 List childIds entityManager.createQuery(select c.id from ChildEntity c where c.rootEntity.id :pid).setParameter(pid, id).getResultList(); for(Long childId : childIds) {entityManager.createQuery(delete from ChildEntity c where c.id :id).setParameter(id, childId).executeUpdate(); } entityManager.createQuery(delete from RootEntity r where r.id :id).setParameter(id, id).executeUpdate(); 上面的代码通过调用remove产生了我们期望的三个SQL语句。 现在您可能会说这种删除方式比仅调用EntityManager的remove方法更为复杂。 它还会忽略我们已放置在两个实体类中的注解例如OneToMany和ManyToOne。 那么为什么不编写一些代码来使用关于两个类文件中已经存在的两个实体的知识呢 首先我们在RootEntity类中使用反射查找OneToMany批注提取子实体的类型然后查找其后向字段并用ManyToOne批注。 完成此操作后我们可以轻松地以更通用的方式编写三个SQL语句 public void delete(EntityManager entityManager, Class parentClass, Object parentId) {Field idField getIdField(parentClass);if (idField ! null) {List oneToManyFields getOneToManyFields(parentClass);for (Field field : oneToManyFields) {Class childClass getFirstActualTypeArgument(field);if (childClass ! null) {Field manyToOneField getManyToOneField(childClass, parentClass);Field childClassIdField getIdField(childClass);if (manyToOneField ! null childClassIdField ! null) {List childIds entityManager.createQuery(String.format(select c.%s from %s c where c.%s.%s :pid, childClassIdField.getName(), childClass.getSimpleName(), manyToOneField.getName(), idField.getName())).setParameter(pid, parentId).getResultList();for (Long childId : childIds) {entityManager.createQuery(String.format(delete from %s c where c.%s :id, childClass.getSimpleName(), childClassIdField.getName())).setParameter(id, childId).executeUpdate();}}}}entityManager.createQuery(String.format(delete from %s e where e.%s :id, parentClass.getSimpleName(), idField.getName())).setParameter(id, parentId).executeUpdate();} } 上面的代码中的方法getFirstActualTypeArgumentgetManyToOneFieldgetIdField和getOneToManyFields并未在此处显示但是听起来像它们的名字。 实施后我们可以轻松删除所有以树的根开头的实体。 可以在github上找到一个可用于检查上述行为和解决方案的简单示例应用程序。 参考在Martins Developer World博客上 使用JPA和Hibernate从我们的JCG合作伙伴 Martin Mois 有效地删除了数据 。 翻译自: https://www.javacodegeeks.com/2013/11/efficiently-delete-data-with-jpa-and-hibernate.html
http://www.sadfv.cn/news/34713/

相关文章:

  • 山东咕果做网站怎么样购物网站模板免费
  • 做电影网站前途池州市建设管理处网站
  • 网站运营经理买手表网站
  • 网站建设费用怎么做分录wordpress 深色主题
  • 做百度网站排名软件企业网站报价模板
  • 网站是先备案 还是先做网站中国建筑工程网施工资料
  • 网站建设客户功能详细要求制作班徽的小程序
  • 网站内容很少如何做seoWordpress虚拟域名
  • 企业建设网站的好处有哪些免费的网站建设
  • 建网站都用什么字体wordpress 修改评论框
  • jsp网站开发什么框架室内设计联盟电脑版
  • 360广告联盟怎么做网站seochan是什么意思
  • 三明鑫龙建设工程网站网页制作设计模板
  • 人事处网站建设绩效目标概述怎么在网上卖东西到国外
  • dw做网站字体做多大项目网站有哪些
  • 安徽合肥做网站wordpress弹窗网页
  • 可以做彩页的网站美容加盟的网站建设
  • html做简单网站实例福州网页定制
  • 贵州省城乡和住房建设厅官方网站吾索源码网
  • 网站建设工作领导小组网站代码规范性
  • 美的集团网站建设建设网站外包
  • 福田莲花网站建设郑州专业做淘宝网站
  • 网站建设银行北京冬奥会纪念币发行时间企业官网建设
  • wordpress怎么建立空白文档河南seo优化
  • 鲜花网网站开发的意义网站开发技术服务协议
  • Joomla外贸网站模板wordpress好用么
  • 万润 企业网站建设大岭山网站仿做
  • 免费建站系统有哪些莱芜二手房出售信息最新房源
  • 产品营销型网站建设携程的网站建设项目规划书
  • 南平做网站中山网站建设文化