`

javax.persistence.MappedSuperclass

阅读更多
@MappedSuperclass
标识一个实体基类,此类不生成对应表;子类继承该基类并用@entry标识,子类生成对应表结构

eg:
 @MappedSuperclass
    public class Employee {
    
        @Id protected Integer empId;
        @Version protected Integer version;
        @ManyToOne @JoinColumn(name="ADDR")
        protected Address address;
    
        public Integer getEmpId() { ... }
        public void setEmpId(Integer id) { ... }
        public Address getAddress() { ... }
        public void setAddress(Address addr) { ... }
    }
    
    // Default table is FTEMPLOYEE table
    @Entity
    @Table(name="t_FTEmployee")  
    public class FTEmployee extends Employee {
    
        // Inherited empId field mapped to FTEMPLOYEE.EMPID
        // Inherited version field mapped to FTEMPLOYEE.VERSION
        // Inherited address field mapped to FTEMPLOYEE.ADDR fk
        
    
    // Defaults to FTEMPLOYEE.SALARY
    
    protected Integer salary;
    
    
    public FTEmployee() {}
    
    
    public Integer getSalary() { ... }
    
    public void setSalary(Integer salary) { ... }
    }



Employee 不生成表,FTEmployee 生成表t_FTEmployee
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics