This is my abstract father:
@MappedSuperclass
public class AbstractEntity{
@ManyToMany
protected Set<UserGroupAccess> userGroupAccesses = new HashSet<>();
@ManyToMany
protected Set<UserAccess> userAccesses = new HashSet<>();
}
these are two entities that inherit the AbstractEntity above:
@Entity
public class Project extends AbstractEntity{
// some other properties
}
@Entity
public class TodoTask extends AbstractEntity{
// some other properties
}
I want in each subclass entity to override and have its table of the relationship represented by userGroupAccesses and userAccesses, I mean for example for Project Entity I need it to have its own table projectuserGroupAccesses and a table projectuserAccesses representing the relationship defined in the AbstractEntity superclass.
Previously I was able to solve such issue using the XML representation of entities, I just define the following in each entity XML:
<set name="userGroupAccesses" table="projectusergroupaccesses" cascade="all-delete-orphan">
<cache usage="read-write" />
<key column="projectid" />
<many-to-many class="org.hisp.dhis.user.UserGroupAccess" column="usergroupaccessid" unique="true" />
</set>
<set name="userAccesses" table="projectuseraccesses" cascade="all-delete-orphan">
<cache usage="read-write" />
<key column="projectid" />
<many-to-many class="org.hisp.dhis.user.UserAccess" column="useraccessid" unique="true" />
</set>
But I still not sure how to do it in the Annotation representation of Entity. I have read about the @AssociationOverrides and @JoinTable I know they are the one I need to solve my issue, but I still couldn't get my head around them.
Can anyone help to explain how to properly use @AssociationOverrides and @JoinTable using my case as an example?