Essentially you will need three entity classes as below:
ActionSet:
@Entity
public class ActionSet {
@OneToMany(mappedBy = "actionSet")
List<ActionSetAction> action;
}
Action:
@Entity
public class Action {
@OneToMany(mappedBy = "action")
List<ActionSetAction> action;
}
ActionSetAction (representing the Join table):
@Entity
public class ActionSetAction {
@ManyToOne
@JoinColumn(name = "action_set_id")
private ActionSet actionSet;
@ManyToOne
@JoinColumn(name = "action_id"
private Action action;
@Column(name ="is_important"
private boolean important;
}
If you want to distinguish between important and unimportant action set actions at the database level rather than in memory then you can look at using the non-JPA Hibernate specific @Where annotation.
@Entity
public class ActionSet {
@OneToMany(mappedBy = "action")
@Where(clause="is_important = true")
List<ActionSetAction> importantActions;
@OneToMany(mappedBy = "action")
@Where("is_important = false")
List<ActionSetAction> unimportantActions;
}
Note that I answered a question recently where I suggested a pure JPA solution to a very similar problem. However, while this worked in EclipseLink there are issues with it in Hibernate.
JPA ManyToMany where annotation