0

我想让 pgId 和 pgName 都作为复合键,其中 pgId 和 pgName 都是分配的值。我不知道我应该怎么做?在网上我得到了复合键列引用其他表的列但不是这种情况的例子?

@Entity
@Table(name = "PersonDetails")
public class PersonDetailsData implements Serializable {
  private static final long serialVersionUID    = 1L;

  @Id
  @Basic
  private int               pgId;

  @Basic(optional = true)
  @Column(nullable = true)
  private int               orgId;

  @Basic(optional = true)
  @Column(nullable = true)
  private String            pgName;


   public PersonWikiDetailsData() {
  }

  public int getPpId() {
    return ppId;
  }

  public void setPpId(int ppId) {
this.ppId = ppId;
  }

  public String getSpaceName() {
return spaceName;
  }

  public void setSpaceName(String spaceName) {
this.spaceName = spaceName;
  }

  }
4

1 回答 1

1

在我们的项目中,我们有一个 Form 实体,它像您的项目一样具有 2 部分主键。

这是复合键类:

@Embeddable
public class FormId implements java.io.Serializable
{
    /** Generated <code>serialVersionUID</code>. */
    private static final long serialVersionUID = 906178514456716120L;

    /** The code of the form. */
    @Column(name = "FRM_CD", nullable = false, length = 80)
    private String formCode;
    /** The version of the form. */
    @Column(name = "FRM_VR", nullable = false, precision = 2, scale = 2)
    private BigDecimal formVersion;

    ...
}

这就是它在 Form 实体中的使用方式:

/** The primary key of the form. */
@EmbeddedId
private FormId formId;
于 2012-04-10T05:39:30.733 回答