休眠中的复合键缺少外键

时间:2020-05-29 12:24:15

标签: java hibernate

am试图在休眠状态下创建复合键,所以我从

开始

SignatureId.java

@Embeddable
public class SignatureId implements Serializable {

   @Column(name = "id_convention")
   private int idConvention;

   @Column(name = "id_participant")
   private int idParticipant;

   public SignatureId(int idConvention, int idParticipant) {
      this.idConvention = idConvention;
      this.idParticipant = idParticipant;
   }

   public SignatureId(int idConvention) {
      this.idConvention = idConvention;
   }

   public SignatureId() {
   }

   @Override
   public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      SignatureId that = (SignatureId) o;
      return Objects.equals(idConvention, that.idConvention) &&
            Objects.equals(idParticipant, that.idParticipant);
   }

   @Override
   public int hashCode() {
      return Objects.hash(idConvention, idParticipant);
   }
} //getters & setters

然后将其应用到我的 Signature.java

@Entity
@Table(name="signature")
public class Signature {

   @EmbeddedId
   private SignatureId id;

   @ManyToOne
   @MapsId("idConvention")
   @JoinColumn(name="id_convention", insertable = false, updatable = false, nullable=false)
   private Convention convention;


   @ManyToOne
   @MapsId("idParticipant")
   @JoinColumn(name="id_participant", insertable = false, updatable = false, nullable=false)
   private Participant participant;

   @Column(name="signature_date")
   private Date signatureDate;


   public Signature(Convention convention, Participant participant) {
      this.convention = convention;
      this.participant = participant;
      this.id = new SignatureId(convention.getIdConvention(), participant.getIdParticipant());
   }

   public Signature() {
   } //getters & setters

问题在于创建数据库时,id_convention缺少外键

enter image description here

是否有一种解决方法可以使id_convention和id_participant都同时具有主键和索引索引?

0 个答案:

没有答案
相关问题