Hello Cuba team.
My case is:
Two tables linked by many to many relationship,
but with an additional field in the help table,
that the user needs to fill out from the interface.
User entity, has a List of help table:
@Composition
@OneToMany(mappedBy="user")
protected List <RoomUser> userRooms;
Room entity, has a List of help table too:
@Composition
@OneToMany(mappedBy="room")
protected List <RoomUser> roomUsers;
The help table, RoomUser has:
@EmbeddedId
protected RoomUserAssociationPK id;
@JoinColumn(name = "room_id")
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@MapsId("roomId")
private Room room;
@JoinColumn(name = "user_id")
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@MapsId("userId")
private User user;
@Column(name = "sequence")
private Integer sequence;
In @Embeddable class RoomUserAssociationPK has:
@MetaClass(name = "app$RoomUserAssociationPK")
@Embeddable
public class RoomUserAssociationPK extends EmbeddableEntity {
private static final long serialVersionUID = 8138145888925579602L;
@Column(name = "room_id")
private Long roomId;
@Column(name = "user_id")
private Long userId;
}
This is the basic structure.
My first question, is the written here is right about this case?
Do I miss something important?
Now.
The Room edit view, has a list and table of help table RoomUser,
which has user Id and sequence field, which User needs to fill.
The sequence field will be editable column in the table.
The roomUserTable has an Add button, which is overrided and redirect to the user browser view
to choose one user:
public void onAddButtonClick() {
roomUsersTableAdd = new AddAction(roomUsersTable);
roomUsersTableAdd.setWindowId("app$User.browse");
roomUsersTable.addAction(roomUsersTableAdd);
}
And now, my logic is to choose a user id and be populate in the help table roomUserTable back into
room edit view, but a room id to be the current room. The sequence field will be filled by the user.
Then save it in the database.
And the same thing with user edit view, and his list of roomUsers.
My problem is when I choose a user in user browser and I need to go back to the room edit view and help table, which be filling in the required information.
Does the logic seem right to you? And how to implement it?
Or there is a sample project with this functionality?
Thank you.