1
我有以下實體:休眠AttributeOverride註解錯誤
public class MyEntity extends AuditableEntity {
@Column
private String name;
}
AuditableEntity
類:
public class AuditableEntity {
@Id
@GenericGenerator(name = "uuid-gen", strategy = "uuid2")
@GeneratedValue(generator = "uuid-gen", strategy = GenerationType.IDENTITY)
private String id;
@CreatedBy
@JsonIgnore
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "user", column = @Column(name = "created_by_id")),
@AttributeOverride(name = "clientId", column = @Column(name = "created_by_client_id"))
})
private AuditorDetails createdBy;
@LastModifiedBy
@JsonIgnore
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "user", column = @Column(name = "last_modified_by_id")),
@AttributeOverride(name = "clientId", column = @Column(name = "last_modified_by_client_id"))
})
private AuditorDetails lastModifiedBy;
}
而且我AuditorDetails
類:
@Embeddable
public class AuditorDetails {
@Column(name = "auditor_client_id")
private String clientId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private User user;
}
另外,我有AuditorAware
返回AuditorDetails
對象。當我嘗試運行此,我有以下異常:
org.hibernate.MappingException:在映射重複列實體: com.aaa.MyEntity柱:USER_ID(應插入=「假」映射 更新=「假」)
但我不能讓該列(S)不能更新,而不是插入的。主要目標是在MyEntity
有4列 - created_by_id
,created_by_client_id
,last_modified_by_id
,last_modified_by_client_id
,它將包含有關行修改和創建的所有數據。如何解決這個異常?