Question

Considérez l'entité JPA suivante. Ma classe demande d'instance doit toujours avoir une référence OneToOne 4 cas particuliers de l'enveloppe, mais il a également un ensemble d'enveloppes définies par l'utilisateur 0-infini. Est-ce seulement possible? Est-il possible avec les deux références unidirectionnelles et / ou bidirectionnelles?

    @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
}
Était-ce utile?

La solution

Vous pouvez le faire avec un mappage de table de jointure:

@OneToMany
@JoinTable( name = "USER_ENVELOPE",
            joinColumns = { @JoinColumn( name = "APP_ID" ) },
            inverseJoinColumns { @JoinColumn( name = "ENVELOP_ID" ) } )        
protected Set<Envelope> userEnvelopes = new HashSet<Envelope>();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top