@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;
}
above my entities that i want to use with beanfieldgroup. If i edit/create a document, i want to add one or more authors (Account) and set an order for these. How can i dynamically create these "JoinTable" with BeanFieldGroup?
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 of the fields in Viritin support ordering out of the box, but at least adding simple up-down arrows should be rather easy.