報錯:No identifier specified for entity: main.java.com.sy.entity.User的解決辦法


自己也沒怎么搭建過框架,更何況還是spring mvc的,最近在帶兩個實習生,正好教他們怎么搭建一個spring mvc的框架,然而我在映射表的時候,提示報錯了。

 

實體基類:

public class BaseEntity implements Serializable{
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    
    @Column(updatable=false)
    protected Date creatTime=new Date();
    
    @Column(updatable=false)
    protected String creatUser;
    
    @Column(insertable=false)
    protected Date updateTime=new Date();
    
    @Column(insertable=false)
    protected String updateUser;

    //get,set方法
}

 

User類:

@Entity
@Table(name="sys_user")
public class User extends BaseEntity {
    
    private String loginName;
    
    private String userName;
    
    private String password;
    
    //get、set方法
    
}

 

代碼看了感覺沒問題啊,查閱國外的論壇之后得出一個結論,自己好菜啊!解決辦法特別簡單!!!在實體基類上加一個@MappedSuperclass

@MappedSuperclass
public class BaseEntity implements Serializable{
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    
    @Column(updatable=false)
    protected Date creatTime=new Date();
    
    @Column(updatable=false)
    protected String creatUser;
    
    @Column(insertable=false)
    protected Date updateTime=new Date();
    
    @Column(insertable=false)
    protected String updateUser;

    //get,set方法

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM