JPA 复合主键源码案例

http://note.youdao.com/share/?id=9065b839f2d6b3f1b6310ad9bb92d3f6&type=note


@Entity
@Table(name = "RELEASE_INFO_ELEMENT")
public class ReleaseInfoElement {
 @EmbeddedId
 private PK pk = new PK();
 @Column(name = "VALUE")
 private String value;
 public Long getInfoId() {
  return pk.infoId;
 }
 public void setInfoId(Long infoId) {
  pk.infoId = infoId;
 }
 public Long getParamId() {
  return pk.paramId;
 }
 @Override
 public String toString() {
  return "ReleaseInfoElement [infoId=" + pk.infoId + ", paramId=" + pk.paramId
    + ", value=" + value + "]";
 }
 public void setParamId(Long paramId) {
  pk.paramId = paramId;
 }
 public String getValue() {
  return value;
 }
 public void setValue(String value) {
  this.value = value;
 }
 @Embeddable
 public static class PK implements Serializable {
  @Column(name = "INFO_ID")
  private Long infoId;
  @Column(name = "PARAM_ID")
  private Long paramId;
  public PK() {
   super();
  }
 }
}

你可能感兴趣的:(JPA 复合主键源码案例)