I have using spring boot. I have used to join three entity to fetch data in repository.But it shows bellow error..
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
I have used bellow code..
my first entity named MenuNameEntity is bellow
@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 }
my second entity is bellow
@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 }
My third entity is bellow
@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 }
My MenuRightRepository is bellow
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(); }
I have used MenuRightResponse to bind the fetched value from repository
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 }
when I called getMenuMenuRights() in MenuRightRepo , it shows above error. I did not use any primary & foreign key.what is the problem of the code. Please help me