BeanFieldGroup 创建嵌套实体

BeanFieldGroup create nested entities

@Entity
public class Document {
    @OneToMany(mappedBy="paper", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    private Set<DocumentAuthor> authors;
}

@Entity
public class DocumentAuthor {
    @Column(name="order")
    @NotNull
    private Integer order;

    @ManyToOne(optional=true, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="account", columnDefinition = "integer")
    private Account account;

    @ManyToOne(optional=false, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="document", columnDefinition = "integer")
    private Document document;
}
@Entity
public class Account {
    @OneToMany(mappedBy="account", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    private Set<DocumentAuthor> papers;
}

在我想与 beanfieldgroup 一起使用的实体之上。如果我 edit/create 一个文档,我想添加一个或多个作者(帐户)并为这些设置顺序。我如何使用 BeanFieldGroup 动态创建这些 "JoinTable"?

Viritin add-on contains many handy helpers to edit this kind of relations. The optimal solution is always domain specific. If you want to create the authors inline you can use ElementCollectionField (example). If you just want your users to choose from an existing set of referred entities, you can use MultiSelectTable (example) or CheckBoxGroup.

None Viritin 中的字段支持开箱即用的排序,但至少添加简单的上下箭头应该相当容易。