Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] @ManyToMany with a discriminator in the @JoinTable

I have a situation where two entities can have a @ManyToMany
relationship with another entity.  In the following case Auditor and
Agent have a collection of Sections associated with them:

public class Agent {
    @Id
    @Column("ID")
     private Long id;

    @ManyToMany
    @JoinTable(
            name="SECTION_MAPPING",
            joinColumns={@JoinColumn(name="ID")},
            inverseJoinColumns={@JoinColumn(name="SECTION_ID")}
        )
     private List<Section> sections;
}


public class Auditor {
    @Id
    @Column("ID")
     private Long id;

    @ManyToMany
    @JoinTable(
            name="SECTION_MAPPING",
            joinColumns={@JoinColumn(name="ID")},
            inverseJoinColumns={@JoinColumn(name="SECTION_ID")}
        )
     private List<Section> sections;
}

I want to model the SECTION_MAPPING table to be something like this:

SECTION_MAPPING ( ID, SECTION_ID, DISCRIMINATOR)

where DISCRIMINATOR has the value of either "auditor" or "agent".

Is there any way I can have a shared @JoinTable so I can avoid
creating two tables like AGENT_SECTIONS and AUDITOR_SECTIONS?

I realize I could achieve this using GUIDs but I don't have that luxury.

Any help is appreciated.

Thanks,
Zarar


Back to the top