“No Persistence Unit Found” error

后端 未结 4 1310
不知归路
不知归路 2021-02-05 09:14

I am getting the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name \'org.springframework.transaction.interc         


        
4条回答
  •  庸人自扰
    2021-02-05 09:38

    This error can happen if you have a hibernate mapped class with relations with another non-mapped class, a solution is to check the relation item as @transient (hibernate will ignore it, use this just to check if this is the error, and later map the related class). Example:

    @Entity
    public class City {
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    
    private String name;
    
    @Transient
    private State state;
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public State getState() {
        return state;
    }
    
    public void setState(State state) {
        this.state = state;
    }
    
    }
    


    And this is the non-mapped class which may give the error:

    public class State {
    
    private String name;
    
    }
    

提交回复
热议问题