I've got 3 classes, one superclass and two subclasses. Each subclass has a collection of the other subclass and I want to map a one to many relationship between them. My superclass is person, and the subclasses are called referrer and broker. The relationship I want to represent is that one referrer can have many brokers and that one broker can have many referrers.
@Component
@Entity
@Table(name="Referrer")
@PrimaryKeyJoinColumn(name="rowID")
public class Referrer extends Person implements Serializable{
private static final long serialVersionUID = 972571370198603227L;
@Column(name="rowId")
private String referrerID;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn
private List<Broker> brokers = new ArrayList<Broker>();
And broker looks like this:
@Component
@Entity
@Table(name="Broker")
@PrimaryKeyJoinColumn(name="rowID")
public class Broker extends Person implements Serializable {
private static final long serialVersionUID = 5648239413711716027L;
@Column(name="AdminID", nullable=true)
private String adminID;
@Column
private boolean isAdmin = false;
@OneToMany(cascade=CascadeType.ALL, mappedBy="referrer")
private List<Referrer> referrers = new ArrayList<Referrer>();
The primary key for Broker should be a field called rowID that is contained within the Person superclass.
I'm really stuck, so any help would be greatly appreciated.