1

我有使用弹簧靴。我曾经加入三个实体来获取存储库中的数据。但它显示以下错误..

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'menuRightRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List...  

Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List

我用过下面的代码..

  1. 我的第一个名为MenuNameEntity的实体如下

    @Entity
    @Table(name = "MenuName")
    public class MenuNameEntity {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
     private long id;
    
     private String parentId;
     private String menuName;
     private String status;
     // getter and setter
     }
    
  2. 我的第二个实体在下面

    @Entity
    @Table(name = "MenuChild")
    public class MenuChildEntity {
    
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
     private long id;   
     private String parentId;   
     private String childMenuName;  
     private String url;    
     private String status;
     //getter and setter
    }
    
  3. 我的第三个实体在下面

    @Entity
    @Table(name = "MenuRight")
    public class MenuRightEntity {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private long id;
    
      private String companyId; 
      private String userId;    
      private String url;   
      private String status;    
      private String enqMode;   
      private String insertMode;    
      private String updateMode;    
      private String deleteMode;
     //getter and setter
     }
    
  4. 我的 MenuRightRepository 如下

     public interface MenuRightRepo extends JpaRepository<MenuRightEntity, Long> {
    
      @Query("select new com.rms.info.MenuRightResponse(m.companyId, m.userId,m.enqMode,m.insertMode,m.updateMode,m.deleteMode, p.parentId,c.childId,c.childMenuName,c.url) from MenuNameEntity p,MenuChildEntity c,MenuRightEntity m where p.parentId = c.parentId  and p.status =1 and c.status =1 and c.url= m.url ")
     List<MenuRightResponse> getMenuMenuRights();   
    
    }
    
  5. 我已经使用MenuRightResponse来绑定从存储库中获取的值

      package com.rms.info;
      public class MenuRightResponse {
    
    private String companyId= "";
    private String userId= "";
    private String enqMode= "";
    private String insertMode= "";
    private String updateMode= "";
    private String deleteMode= "";
    private String parentId= "";
    private String childId= "";
    private String childMenuName= "";
    private String url= "";     
    
      public MenuRightResponse(String companyId, String userId, String enqMode, String insertMode, String updateMode,
        String deleteMode, String parentId, String childId, String childMenuName, String url) {
    super();
    this.companyId = companyId;
    this.userId = userId;
    this.enqMode = enqMode;
    this.insertMode = insertMode;
    this.updateMode = updateMode;
    this.deleteMode = deleteMode;
    this.parentId = parentId;
    this.childId = childId;
    this.childMenuName = childMenuName;
    this.url = url;
      }
    //getter and setter
     }
    

当我在 MenuRightRepo 中调用 getMenuMenuRights() 时,它显示了上述错误。我没有使用任何主键和外键。代码有什么问题。请帮我

4

1 回答 1

0

我已经解决了下面的问题......

  1. 我已将MenuNameEntity 更改为

    @Entity
    @Table(name = "MenuName")
    public class MenuNameEntity {
    
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
     private long id;
    
    private String parentId;
    private String menuName;
    private String status;
    
     @OneToMany(fetch = FetchType.LAZY, mappedBy = "MenuName")  
     private Set<MenuChildEntity> menuChildEntities;
    
    // getter and setter
    }
    
  2. 我已将MenuChildEntity 更改为

    @Entity
    @Table(name = "MenuChild")
    public class MenuChildEntity {
    
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
     private long id; 
    
     @Column(name = "parentId", nullable = false,insertable = false,updatable = false) 
     private String parentId;   
     private String childMenuName;  
     private String url;    
     private String status;
    
     @OneToMany(fetch = FetchType.LAZY, mappedBy = "MenuChild") 
     private Set<MenuRightEntity> menuRightEntities;
    
     @ManyToOne
     @JoinColumn(name = "parentId")
     private MenuNameEntity MenuName;
    
     //getter and setter
     }
    
  3. 我已将MenuRightEntity 更改为

    @Entity
    @Table(name = "MenuRight")
    public class MenuRightEntity {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
     private long id;
    
     private String companyId; 
     private String userId;  
    
    @Column(name = "url", nullable = false,insertable = false,updatable = false)  
     private String url;   
     private String status;    
     private String enqMode;   
     private String insertMode;    
     private String updateMode;    
     private String deleteMode;        
    
     @ManyToOne
     @JoinColumn(name = "url")
     private MenuChildEntity MenuChild;
    
      //getter and setter
    
     }
    

然后我的存储库查询工作正常...我只是加入三个表无条件一对多和多对一并加入列可为空的 false工作正常

于 2020-07-02T18:25:55.143 回答