在Hibernate中创建UPDATE RETURNING查询

编程入门 行业动态 更新时间:2024-10-08 00:33:14
本文介绍了在Hibernate中创建UPDATE RETURNING查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Oracle中,我们可以创建一个更新查询,该查询将使用RETURNING子句返回更新的记录.

Hibernate中是否有类似的功能?

解决方案

除了数据库生成的值外,显然Hibernate也不需要返回更新后的实例,因为传递给Session.saveOrUpdate() 的对象是更新的实例.如果对数据库生成的值(顺序,触发器,默认值等)进行了相应注释(或在XML映射文件中定义),则将在 Session.saveOrUpdate之后设置它们.

对于标识符值与JPA @javax.persistence.Id注释结合使用JPA @javax.persistence.GeneratedValue注释.对于简单属性使用本地的Hibernate @org.hibernate.annotations.Generated注释(afaik没有相应的JPA注释).

Hibernate如何检索生成的标识符值取决于生成策略和/或数据库方言.对于简单属性,Hibernate在INSERT或UPDATE之后通过id语句执行附加的SELECT.

In Oracle we can create an update query that will return the updated record using the RETURNING clause.

Is there similar functionality in Hibernate?

解决方案

Apart from database-generated values there is obviously no need for Hibernate to return the updated instance because the object passed to Session.saveOrUpdate() is the updated instance. Database-generated values (sequence, trigger, defaults, etc.) will be set after Session.saveOrUpdate if they are accordingly annotated (or defined in a XML mapping file).

For identifier values use the JPA @javax.persistence.GeneratedValue annotation in conjunction with the JPA @javax.persistence.Id annotation. For simple properties use the native Hibernate @org.hibernate.annotations.Generated annotation (afaik there is no according JPA annotation).

How generated identifier values are retrieved by Hibernate depends on the generation strategy and/or the database dialect. For simple properties Hibernate executes an additional SELECT by id statement after the INSERT or UPDATE.

更多推荐

在Hibernate中创建UPDATE RETURNING查询

本文发布于:2023-10-26 06:43:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Hibernate   UPDATE   RETURNING

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!