ShaggyInjun
ShaggyInjun

Reputation: 2963

Composite key and many to one

I need a field to be part of the composite key, but I also need a Many to one relationship with the corresponding object. Is something like this possible ?

@Entity
public class Instrument {

    @EmbeddedId
    private InstrumentPk instrumentPk;

    @ManyToOne;
    private Transaction transaction;

}

@Embeddable
public class InstrumentPk {

    private Integer productId;

    private Integer transId;

}

Upvotes: 1

Views: 53

Answers (1)

Andronicus
Andronicus

Reputation: 26046

In your case @ManyToOne relationship has nothing to do with @Embeddable:

@ManyToOne;
private Transaction transaction;

This is goig to work just fine provided there is a Transaction entity and mapping is well defined.

Upvotes: 2

Related Questions