@ javax.persistence.Column(updatable = false) [英] @javax.persistence.Column( updatable=false )

查看:154
本文介绍了@ javax.persistence.Column(updatable = false)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将字段定义为不可更新,这是否意味着该字段根本无法更新?我想要做的是在保存整个实体对象时阻止字段更新,但仍然能够编写显式更新此字段的查询。这可能吗?

If I define a field as non-updatable, does that mean that the field can't be updated at all, ever? What I'd like to do is prevent the field from getting updated when I save an entire entity object, but still be able to write queries that explicitly update this field. Is this possible?

我正在使用Hibernate和MySQL,但我更喜欢编写可移植代码。

I'm using Hibernate and MySQL, but I'd prefer to write portable code.

推荐答案

as 记录,设置 updatable = false 仅影响持久性提供程序生成的SQL UPDATE语句:

As documented, setting updatable=false affects only SQL UPDATE statements generated by persistence provider:


该列是否包含在
持久性提供程序生成的SQL UPDATE语句中。

Whether the column is included in SQL UPDATE statements generated by the persistence provider.

您仍然可以编写这样的SQL更新语句来更新此列中的值。此功能在JPA规范中定义,而不是特定于Hibernate / MySQL。

You are still able to write such an SQL update statement that will update values in this column. This functionality defined in JPA specification, and is not Hibernate/MySQL specific.

这篇关于@ javax.persistence.Column(updatable = false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆