hibernate union primary key annotation method

Method 1: The primary key class uses @Embeddable, the pojo class still uses @Entity but the object that refers to the primary key class uses the @Id 

primary key pojo class: 

@Embeddable
public class composeIdPK implements Serializable {
 private String name;
 private int id;
  @Column(length=20,name="pkName")
 public String getName() {
  return name;
 }
    @Column(length=10,name="uuid")
 public int getId() {
  return id;
 }

 

pojo type: 

@Entity
public class composeId {
 private composeIdPK pk;
 private int uid;
 private String title;
 private String address;
 
 @Id
 public composeIdPK getPk() {
  return pk;
 }

 

Method 2: @EmbeddedlD(*) The primary key pojo class does not need to be annotated with @EmbeddedlD, just write @EmbeddedlD before the get method of the new property "composeIdPK" of the pojo class 

Method 3: @Id @IdClass(*) The primary key pojo class does not need to be Add annotation, the id and name attributes of the original pojo class remain unchanged, and there is no need to add the "ComposeIDPK" attribute. Only add @Id before the get method of id and name, and add the 

following before the original pojo class: 

@Entity
@IdClass(com.study.model.composeID.composeIdPK.class)
public class composeId {
 //private composeIdPK pk;
    private int id;
    private String name;
    @Id
    @Column(length=10,name="uuid")
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 @Id
  @Column(length=20,name="pkName")
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 private String title;
 private String address;

 

This article is reproduced, the source is not found.. Sorry!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324889030&siteId=291194637