联合主键做外键

一.创建PK类

import java.io.Serializable;

public class PKCode implements Serializable {
    
    private Integer code;
    
    private Integer codeType;
    
    public Integer getCode() {
        return code;
    }
    
    public void setCode(Integer code) {
        this.code = code;
    }
    
    public Integer getCodeType() {
        return codeType;
    }
    
    public void setCodeType(Integer codeType) {
        this.codeType = codeType;
    }
    
    public boolean equals(Object obj) {
        return super.equals(obj);
    }
    
    public int hashCode() {
        return super.hashCode();
    }
}

 二.创建实体

public class Code extends MainEntity {
    
    private PKCode codePk;
    
    private String name;
    
    public PKCode getCodePk() {
        return codePk;
    }
    
    public void setCodePk(PKCode codePk) {
        this.codePk = codePk;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
}
 
public class CodeType extends MainEntity {
    
    private String name;
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
}

 三.创建映射文件






	
		
			
			
		
	

 四.联合主键做外键



	
	
 

你可能感兴趣的:(HIBERNATE,java)