embeddeble为空,因此审核不起作用

yhuiod9q  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(264)

我有以下可嵌入的

@Data
@Embeddable
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BaseEntity {

  @CreatedDate
  @Column(name = "created_date")
  private LocalDateTime createdDate;
}

我把它嵌入了另一个实体

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "room")
@Builder
public class room {

  @Id
  @GeneratedValue
  private UUID id;

  @JsonUnwrapped
  @Embedded
  private BaseEntity baseEntity;

  @Column(length = 80, nullable = false)
  private String name;
}

现在,当我保存一个文件室实体时,嵌入的baseentity为null,这就是为什么没有审计任何内容。根据https://docs.spring.io/spring-data/commons/docs/2.4.4/reference/html/#auditing.annotations 应该是这样的。我怎样才能纠正这种行为?

fdbelqdn

fdbelqdn1#

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "room")
@Builder
public class room {

...

  @JsonUnwrapped
  @Embedded
  private BaseEntity baseEntity = new BaseEntity();

...
}

相关问题