仅与JaVers比较具体注释的属性?

时间:2017-07-18 10:18:28

标签: hibernate orm annotations detach javers

我有以下域名模型。 NB Jackson @Json查看字段的注释:

public interface JSONInvoiceBasicView {

    }

    public interface JSONInvoiceWithLinesView extends JSONInvoiceBasicView {

    }

    public interface JSONInvoiceWithLinesViewExt extends JSONInvoiceWithLinesView { 
    }

}

@PersistenceUnit(unitName="ERP_PU")
@Entity 
@Table(name="INVOICE")
public class Invoice extends FrameworkEntity {

    @Id
    @SequenceGenerator(name = "PK_INVOICE_GEN", sequenceName = "PK_INVOICE_GEN", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PK_INVOICE_GEN")
    @Column(name = "ID")
    @JsonView(JSONInvoiceView.JSONInvoiceBasicView.class)
    private Long id;

    @OneToMany(mappedBy="invoiceLine", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
    @JsonManagedReference
    private List<InvoiceLine> lines = new ArrayList<InvoiceLine>();

    @Temporal(TemporalType.DATE)
    @Column(name = "DATE")
    @JsonView(JSONInvoiceView.JSONInvoiceBasicView.class)
    private Date startDate;

    //...
}

@PersistenceUnit(unitName="ERP_PU")
@Entity 
@Table(name="INVOICE_LINE")
public class InvoiceLine extends FrameworkEntity {

    @Id
    @Column(name = "ID")
    @JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
    @JoinColumn(name="FK_INVOICE")
    @JsonBackReference
    private Invoice invoice;

    @Column(name = "AMOUNT")
    @JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)
    private BigDecimal amount;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
    @JoinColumn(name="FK_GOOD")
    @JsonView(JSONInvoiceView.JSONInvoiceWithLinesExtView.class)
    private Good good;

    //...
}
@PersistenceUnit(unitName="ERP_PU")
@Entity 
@Table(name="GOOD")
public class Good extends FrameworkEntity {

    @Id
    @Column(name = "ID")
    private Long id;

    @Column(name = "DESCRIPTION", length=200)
    private String description;

//...
}

所以 - 我的问题是我只检索整个对象图的子图,例如只有Invoice和InvoiceLine实体,其字段用@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)注释,即我没有进一步,我没有检索invoice.invoiceLine [i] .good实体。我的问题是 - 我可以修剪JaVers差异进程,我可以要求JaVers只比较对象图的子集 - 例如注释的子集使用@JsonView(JSONInvoiceView.JSONInvoiceWithLinesView.class)

我的问题提到了关于实体领域的Jackson @JsonView注释,但我想 - 如果JaVers支持对观察到的属性进行过滤,那么这个过滤可以通过适用于字段/属性的任何注释集来完成 - 无论是Jackson还是自定义创建

我听说过@DiffIgnore JaVers anotation,我正在寻找这种机制的概括和精简。

我的情况是 - 我正在检索子图,我发送ir到Angular fronent,然后我从Angular获得更新的子图,我想将它合并回我的后端。

1 个答案:

答案 0 :(得分:1)

没有这样的诱饵,您可以通过指向特定的注释来过滤要比较的属性。

你所能做的只是使用JaVers&#39;注释: @DiffIgnore@ShallowReference@IgnoreDeclaredProperties。 您也可以在类/接口级别全局使用它们。

请参阅https://javers.org/documentation/domain-configuration/#ignoring-things