使用JPA将某些字段的值设置为null [英] setting values of some fields to null using JPA
问题描述
在jpa合并中,是否所有列都已更新或仅具有新值的列?
In jpa merge, are all coumns updated or only the columns which have new values?
在更新时,如果我将某些属性的值设置为null,则将null值存储在db的该存储区中,还是保留先前的值?
While updating if i set value of some attribute to null, will null value will be stored in that cloumn in db, or will it retain previous value?
推荐答案
合并实体X时,X的整体状态将被合并"(如果X是X的有效候选")课程). JPA 1.0规范如下所示:
When merging an entity X, the whole state of X will be "merged" (if X is a valid "candidate" of course). The JPA 1.0 specification puts it like this:
3.2.4.1合并独立的实体状态
合并操作允许 脱离状态的传播 实体到持久实体 由EntityManager管理.
3.2.4.1 Merging Detached Entity State
The merge operation allows for the propagation of state from detached entities onto persistent entities managed by the EntityManager.
合并操作的语义 应用于实体X的情况如下:
The semantics of the merge operation applied to an entity X are as follows:
- 如果X是独立实体,则 X的状态将被复制到预先存在的实体上 相同的管理实体实例X' 身份或X的新托管副本X' 已创建.
- 如果X是一个新的实体实例,则创建一个新的受管实体实例X' 并将X的状态复制到 新的受管实体实例X'.
- 如果X是已删除的实体实例,则
IllegalArgumentException
将是 由合并操作(或 事务提交将失败). - 如果X是一个受管实体,则合并操作会忽略它,
但是,合并操作是
级联到所引用的实体
来自X的关系(如果有)
关系已被注释为
级联元素值
cascade=MERGE
或cascade=ALL
注释. - 对于由X的关系引用的所有具有Y的实体Y
级联元素值
cascade=MERGE
或cascade=ALL
,Y递归合并 作为Y'.对于所有由 X,X'设置为参考Y'. (笔记 如果X被管理,那么X是 与X'是同一对象.) - 如果X是合并到X'的实体,并引用另一个实体Y,则其中
cascade=MERGE
或cascade=ALL
是 未指定,则导航 X'的相同关联产生a 引用管理对象Y' 与Y具有相同的持久身份.
- If X is a detached entity, the state of X is copied onto a pre-existing managed entity instance X' of the same identity or a new managed copy X' of X is created.
- If X is a new entity instance, a new managed entity instance X' is created and the state of X is copied into the new managed entity instance X'.
- If X is a removed entity instance, an
IllegalArgumentException
will be thrown by the merge operation (or the transaction commit will fail). - If X is a managed entity, it is ignored by the merge operation,
however, the merge operation is
cascaded to entities referenced by
relationships from X if these
relationships have been annotated with
the cascade element value
cascade=MERGE
orcascade=ALL
annotation. - For all entities Y referenced by relationships from X having the
cascade element value
cascade=MERGE
orcascade=ALL
, Y is merged recursively as Y'. For all such Y referenced by X, X' is set to reference Y'. (Note that if X is managed then X is the same object as X'.) - If X is an entity merged to X', with a reference to another entity Y, where
cascade=MERGE
orcascade=ALL
is not specified, then navigation of the same association from X' yields a reference to a managed object Y' with the same persistent identity as Y.
持久性提供程序不得 合并标记为LAZY的字段,这些字段没有 被获取:它必须忽略这样的 合并时的字段.
The persistence provider must not merge fields marked LAZY that have not been fetched: it must ignore such fields when merging.
实体必须由
持久性运行时实现
在合并操作期间和/或
刷新或提交时间.离席期间
Version
列中没有
进行的附加版本检查
持久性提供程序运行时
在合并操作期间.
Any Version
columns used by the
entity must be checked by the
persistence runtime implementation
during the merge operation and/or at
flush or commit time. In the absence
of Version
columns there is no
additional version checking done by
the persistence provider runtime
during the merge operation.
这篇关于使用JPA将某些字段的值设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!