CUBA 5.4.6
При добавлении сущности со связью многие-ко многим источник данных не помечается как modified. Из-за этого не сохраняются измененные коллекции (связи). В случае при редактировании сущности с ведущей связью, связь сохраняется, но удаление связи не сохраняется . В случае с ведомой (mapped by) связь не сохряняется при добавлении и не сохраняется удаленная связь.
EntityOne.java
public class EntityOne extends StandardEntity {
@Composition
@ManyToMany(mappedBy = "entities")
protected Set<EntityTwo> entities;
}
entity-one-edit.xml
<window xmlns="http://schemas.haulmont.com/cuba/5.4/window.xsd"
>
<dsContext>
<datasource id="entityDs" class="org.company.project.entity.EntityOne " view="entity-edit">
<collectionDatasource id="twosDs" property="entities"/>
</datasource>
</dsContext>
<layout>
<table id="twosTable">
<actions>
<action id="add"/>
<action id="exclude"/>
</actions>
<buttonsPanel>
<button action="twosTable.add"/>
<button action="twosTable.exclude"/>
</buttonsPanel>
<columns>
<column id="id"/>
</columns>
<rows datasource="activities"/>
</table>
</layout>
</window>
EntityTwo.java
public class EntityTwo extends StandardEntity {
@Composition
@ManyToMany
@JoinTable(name = "PROJECT_ONE_TWO",
joinColumns = {@JoinColumn(name = "ENTITY_TWO_ID")},
inverseJoinColumns = {@JoinColumn(name = "ENTITY_ONE_ID")})
protected Set<EntityOne> entities;
}
entity-two-edit.xml
<window xmlns="http://schemas.haulmont.com/cuba/5.4/window.xsd"
>
<dsContext>
<datasource id="entityDs" class="org.company.project.entity.EntityTwo " view="entity-edit">
<collectionDatasource id="onesDs" property="entities"/>
</datasource>
</dsContext>
<layout>
<table id="onesTable">
<actions>
<action id="add"/>
<action id="exclude"/>
</actions>
<buttonsPanel>
<button action="onesTable.add"/>
<button action="onesTable.exclude"/>
</buttonsPanel>
<columns>
<column id="id"/>
</columns>
<rows datasource="onesDs"/>
</table>
</layout>
</window>