有没有办法用休眠 - envers来审计,一个在其嵌入式Id中具有@Embedded的实体

我有一个实体集团记录具有复合代码BlocRecordId,并且在其复合代码中有一个@Embedded(关系代码ManyToOne)指向另一个原始记录并希望审核实体集团记录。


实体集团记录


@Entity

@Inheritance(strategy = InheritanceType.JOINED)

@Table(name = "blocRecord")

@Access(value = AccessType.FIELD)

@Audited

public class BlocRecord {


    @EmbeddedId


    private BlocRecordId blocRecordId = new BlocRecordId();


    @ManyToOne(fetch = FetchType.LAZY, optional = false)

    @JoinColumns({

            @JoinColumn(name = "record_identifier_", referencedColumnName = "identifier_", unique = false, nullable = false),

            @JoinColumn(name = "record_recordType_", referencedColumnName = "recordType_", unique = false, nullable = false)})

    @MapsId("record")

    private Record record;


...


}

标识类块记录 ID


@Embeddable

public class BlocRecordId implements Serializable {



    @Embedded

    private RecordId record;


    @Column(name = "source_")

    String source ;


    @Column(name = "messageType_")

    String messageType ;


实体记录


@Entity

@Inheritance(strategy = InheritanceType.JOINED)

@Table(name = "records")

@Access(value = AccessType.FIELD)

@Audited

public class Record {


    @EmbeddedId

    private RecordId recordId = new RecordId();



    @OneToMany(targetEntity = BlocRecord.class, fetch = FetchType.LAZY, mappedBy = "record")

    private Set<BlocRecord> blocRecord = new java.util.HashSet<>();


...

}

实体记录的 id 类


@Embeddable

public class RecordId implements Serializable{


    @Column(name = "identifier_")

    String identifier ;


    @Column(name = "recordType_")

    String recordType ;


}

休眠 -envers 在尝试在可嵌入的 BlocRecordId 中生成字段记录的元数据时失败,引发流动异常

您知道如何解决问题吗?


噜噜哒
浏览 65回答 1
1回答

猛跑小猪

目前,Envers 不支持在可嵌入对象中嵌套嵌入对象的想法,当我们映射标识符列时,如您的示例所示。Envers 目前支持的唯一有效映射是可嵌入对象中的属性是 a 或 类型。@ManyToOne@Basic您可以解决此问题,但它涉及更明确一点,而不是使用。我的意思是重写如下:RecordIdBlocRecordId@Embeddablepublic class BlocRecordId implements Serializable {&nbsp; @Column(name = "identifier_")&nbsp; String identifier;&nbsp; @Column(name = "recordType_")&nbsp; String recordType;&nbsp; @Column(name = "source_")&nbsp; String source;&nbsp; @Column(name = "messageType_")&nbsp; String messageType;&nbsp; @Transient&nbsp; private RecordId recordId;&nbsp; /** Helper method to assign the values from an existing RecordId */&nbsp; public void setRecordId(RecordId recordId) {&nbsp; &nbsp; this.identifier = recordId.getIdentifier();&nbsp; &nbsp; this.recordType = recordId.getRecordType();&nbsp; }&nbsp; /** Helper method to get the RecordId, caching it to avoid multiple allocations */&nbsp; public RecordId getRecordId() {&nbsp; &nbsp; if ( recordId == null ) {&nbsp; &nbsp; &nbsp; this.recordId = new RecordId( identifier, recordType );&nbsp; &nbsp; }&nbsp; &nbsp; return this.recordId;&nbsp; }}我同意这并不理想,但它至少可以解决代码的当前限制。我已经添加并添加了HHH-13361作为开放问题来支持这一点。如果您愿意,欢迎您做出贡献,或者我将努力为Envers 6.0提供此支持。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java