添加到@ManyToMany集合时休眠@UpdateTimestamp

时间:2019-06-05 14:00:06

标签: hibernate jpa spring-data-jpa

让我们假设这样的实体:

@Entity
public class Entity {

  @Id
  @GeneratedValue
  private Long id;

  private String name;

  @ManyToMany
  @JoinTable
  private Set<SomeOtherEntity> someOtherEntities= new HashSet<>();

  @CreationTimestamp
  private LocalDateTime creationTimestamp;

  @UpdateTimestamp
  private LocalDateTime lastUpdateTimestamp;
}

(省略设置者,获取者)

当我更新name字段值时,lastUpdateTimestamp会按预期更新,但是当我向SomeOtherEntity添加一些someOtherEntities时,lastUpdateTimestamp不变,这可能是预期的行为,因为Entity实体未更改,但是@JoinTable中有一个新插入。有人知道lastUpdateTimestamp内容被修改后如何触发someOtherEntities的更新吗?

0 个答案:

没有答案