Reputation: 33571
Consider the following JPA entity. My application instance class must always have a OneToOne reference to 4 special instances of Envelope but it also has a set of 0-infinite user defined envelopes. Is this even possible? Is it possible with both Unidirectional and/or Bidirectional references?
@Entity(name = "Application_Instance")
public class ApplicationInstance implements Serializable {
@Id
private int databaseId;
private Envelope accountTransfersEnvelope = new Envelope("Account Transfers");
@OneToOne
private Envelope newTransationsEnvelope = new Envelope("New Transactions");
@OneToOne
private Envelope incomeEnvelope = new Envelope("Income Envelope");
@OneToOne
private Envelope creditCarEnvelope= new Envelope("Credit Card");
@OneToMany
protected Set<Envelope> userEnvelopes = new HashSet<Envelope>();
//rest of class
}
Upvotes: 2
Views: 1252
Reputation: 5569
You could do this with a join table mapping:
@OneToMany
@JoinTable( name = "USER_ENVELOPE",
joinColumns = { @JoinColumn( name = "APP_ID" ) },
inverseJoinColumns { @JoinColumn( name = "ENVELOP_ID" ) } )
protected Set<Envelope> userEnvelopes = new HashSet<Envelope>();
Upvotes: 2