从getMenusByRole中的多个表中获取数据时,我收到 org.springframework.dao.InvalidDataAccessResourceUsageException 异常。我的查询是正确的,并在数据库上给出预期的结果 以下是代码段 -
UserDaoImpl.java
package com.msoft.crm.daos;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;
import org.w3c.dom.ls.LSInput;
import com.msoft.crm.entities.Users;
@Repository("UserDao")
public class UserDaoImpl implements UserDao {
@PersistenceContext
private EntityManager entityManager;
public String original,recipientAddress,firstName,userName;
@Override
public List<Users> getAllUsers() {
return new ArrayList<Users>();
}
@Override
public List<Users> validateLogin(String username, String password) {
String hql = "from Users u where u.username = :p_username and u.userPassword = :p_password";
Query q = entityManager.createQuery(hql);
q.setParameter("p_username", username);
q.setParameter("p_password", password);
List<Users> users = q.getResultList();
System.out.println("users : " + users);
return users;
}
@Override
public List<Users> getMenusByRole(long userId) {
String hql = " select ur.role_id ,ur.role_name ,ur.speciality ,ms.section_id ,ms.section_name ,ms.section_position ,"
+ "ms.section_icon ,mi.menu_id ,mi.menu_name ,mi.menu_action ,mi.menu_position ,mi.parent_menu_id "
+ "from MenuPrivileges mp inner join UserRoles ur on mp.role_id = ur.role_id "
+ "inner join MenuItems mi on mp.menu_id = mi.menu_id "
+ "inner join MenuSections ms on mi.section_id = ms.section_id "
+ "where mi.active_ind = '1' and mp.visible_ind = '1' "
+ "and mp.role_id = (select role_id from crm_users where user_id = :user_id) order by ms.section_position asc";
Query q = entityManager.createNativeQuery(hql);
q.setParameter("user_id", userId);
List<Users> l = q.getResultList();
System.out.println("l : " + l);
return l;
}
}
MenuPrivileges.java
package com.msoft.crm.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="crm_menu_privileges")
public class MenuPrivileges {
@Id
@Column
private int role_id;
@Column
private int menu_id;
@Column
private String visible_ind;
public MenuPrivileges() {
this(0,0,"");
}
public MenuPrivileges(int role_id, int menu_id, String visible_ind) {
this.role_id = role_id;
this.menu_id = menu_id;
this.visible_ind = visible_ind;
}
//getter and setter
}
UserRoles.java
@Entity
@Table(name="crm_user_roles")
public class UserRoles {
@Id
@Column
private int role_id;
@Column
private String role_name;
@Column
private String speciality;
// getters and setters
}
MenuItems.java
@Entity
@Table(name="crm_menu_items")
public class MenuItems {
@Id
@Column
private int section_id;
@Column
private int menu_id;
@Column
private String menu_name;
@Column
private String menu_desc;
@Column
private String menu_action;
@Column
private int menu_position;
@Column
private int parent_menu_id;
@Column
private String active_ind;
// getter and setter
}
MenuSections.javv
@Entity
@Table(name="crm_menu_sections")
public class MenuSections {
@Id
@Column
private int id_pk;
@Column
private int section_id;
@Column
private String section_name;
@Column
private String section_desc;
@Column
private String section_icon;
@Column
private int section_position;
//getter and setter
}
以下是我的堆栈跟踪,其中两个查询都正在运行但是getMenuByRole上面提到了异常。
Hibernate:
select
users0_.user_id as user_id1_5_,
users0_.aadhar_no as aadhar_n2_5_,
users0_.active_ind as active_i3_5_,
users0_.created_by_user_id as created_4_5_,
users0_.created_date_time as created_5_5_,
users0_.email as email6_5_,
users0_.fname as fname7_5_,
users0_.lname as lname8_5_,
users0_.login_status as login_st9_5_,
users0_.mname as mname10_5_,
users0_.mobile as mobile11_5_,
users0_.photo as photo12_5_,
users0_.role_id as role_id13_5_,
users0_.password as passwor14_5_,
users0_.username as usernam15_5_
from
crm_users users0_
where
users0_.username=?
and users0_.password=?
users : [Users [userId=3, roleId=1, sectionId=0, sectionPosition=0, menuId=0, menuPosition=0, parentMenuId=0, specialityId=0, username=shirin, activeInd=1, loginStatus=1, roleName=null, speciality=null, sectionName=null, sectionIcon=null, menuName=null, menuAction=null, firstName=yogiraj, lastName=kulkarni, mobileNumber=9699999999, middleName=, emailAddress=yogirajk@msoft.co.in, aadhaarNumber=123456987456, profileImg=data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxITEhUSEhIVFRUVFRUVFRUVFRAVFhUVFRUWFhUVFRUYHSggGBolHRUVITEhJSkrLi4uFx8zODMtNygtLisBCgoKDg0OGxAQGy0lHyUtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSstLS0tLS0tLS0tLS0tLS0tLS0tLS0tLf/AABEIALcBEwMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAADAAIEBQYBBwj/xAA9EAABAwIEAwUGBAQGAwEAAAABAAIRAyEEBRIxQVFhBiJxgaETMpGxwdEUQlLwI6Lh8QczQ2JykiRTgxX/xAAbAQACAwEBAQAAAAAAAAAAAAADBAECBQAGB//EAC0RAAICAQMCBQIGAwAAAAAAAAABAhEDBBIhMUEFEyJRYTJxI1KBobHwFEKR/9oADAMBAAIRAxEAPwCwxGWADZY/NKUVCF6tmVBunyXm2dM/iFKXQWXBTFiYWqY5qjhqlSsHYwWQatVErKJUClOybOe1RKZUUboocr0SWFJ6kB6radRHFRQyCZ7REpAlNy7BOqHotZhMoAGy6MGyGZ0Unckx7DxC15y8DgomJwA5KXiZKZlHFJrkfNMI5twLKvaSh1RYnMKKHqJTRgVBwX2ia4oRK5rXHBkwtXA9OUnAKjFHJU14USoFJwXB3V1hcMdQKq8lZLoW0pYYBoKLCNg5FllNKIWlpYW0rO4arELWZbWBCZiiKK3E4boqjGYexWvxNGQs9jqcSuaJPNe0lCxWSJW47UcVhX7pWS5LREShPKcXIbioLEchJPhJSce7Z1iwAvP8wdqeSrnOcwm0qgmUjmnXAPNLsR6oshtZZHqhItso31AHu4IT6aiYkQrY07KpxhuiYZ7pUdB2yEUVtMo2GoTdSH0oRpZUnRdy5oisCm4DCmo4BCp0SVpezOGGra/FWvmi/RGiyjLQ1ostBSwgTM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/9k=, fullName=null, userPassword=e7202d28c87440d38bd5bf4ff37c7fcc, createdBy=1, createdDate=2017-06-14 11:16:12.0]]
active ind(service):1
In get menus role user id : 3
Hibernate:
select
ur.role_id ,
ur.role_name ,
ur.speciality ,
ms.section_id ,
ms.section_name ,
ms.section_position ,
ms.section_icon ,
mi.menu_id ,
mi.menu_name ,
mi.menu_action ,
mi.menu_position ,
mi.parent_menu_id
from
MenuPrivileges mp
inner join
UserRoles ur
on mp.role_id = ur.role_id
inner join
MenuItems mi
on mp.menu_id = mi.menu_id
inner join
MenuSections ms
on mi.section_id = ms.section_id
where
mi.active_ind = '1'
and mp.visible_ind = '1'
and mp.role_id = (
select
role_id
from
crm_users
where
user_id = ?
)
order by
ms.section_position asc
2017-11-07 10:27:47.364 WARN 3116 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1146, SQLState: 42S02
2017-11-07 10:27:47.364 ERROR 3116 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : (conn:143322) Table 'crm_application.MenuPrivileges' doesn't exist
Query is: select ur.role_id ,ur.role_name ,ur.speciality ,ms.section_id ,ms.section_name ,ms.section_position ,ms.section_icon ,mi.menu_id ,mi.menu_name ,mi.menu_action ,mi.menu_position ,mi.parent_menu_id from MenuPrivileges mp inner join UserRoles ur on mp.role_id = ur.role_id inner join MenuItems mi on mp.menu_id = mi.menu_id inner join MenuSections ms on mi.section_id = ms.section_id where mi.active_ind = '1' and mp.visible_ind = '1' and mp.role_id = (select role_id from crm_users where user_id = ?) order by ms.section_position asc, parameters [3]
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:261)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:488)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.msoft.crm.daos.UserDaoImpl$$EnhancerBySpringCGLIB$$337e38b5.getMenusByRole(<generated>)
at com.msoft.crm.services.UserService.validateLogin(UserService.java:44)
at com.msoft.crm.controllers.LoginController.validateLogin(LoginController.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2117)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876)
at org.hibernate.loader.Loader.doQuery(Loader.java:919)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2617)
at org.hibernate.loader.Loader.doList(Loader.java:2600)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
at org.hibernate.loader.Loader.list(Loader.java:2424)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1967)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483)
at com.msoft.crm.daos.UserDaoImpl.getMenusByRole(UserDaoImpl.java:115)
at com.msoft.crm.daos.UserDaoImpl$$FastClassBySpringCGLIB$$da03a52e.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 59 more
Caused by: java.sql.SQLSyntaxErrorException: (conn:143322) Table 'crm_application.MenuPrivileges' doesn't exist
Query is: select ur.role_id ,ur.role_name ,ur.speciality ,ms.section_id ,ms.section_name ,ms.section_position ,ms.section_icon ,mi.menu_id ,mi.menu_name ,mi.menu_action ,mi.menu_position ,mi.parent_menu_id from MenuPrivileges mp inner join UserRoles ur on mp.role_id = ur.role_id inner join MenuItems mi on mp.menu_id = mi.menu_id inner join MenuSections ms on mi.section_id = ms.section_id where mi.active_ind = '1' and mp.visible_ind = '1' and mp.role_id = (select role_id from crm_users where user_id = ?) order by ms.section_position asc, parameters [3]
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:139)
at org.mariadb.jdbc.internal.util.ExceptionMapper.getException(ExceptionMapper.java:101)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwAndLogException(ExceptionMapper.java:77)
at org.mariadb.jdbc.MariaDbStatement.executeQueryEpilog(MariaDbStatement.java:226)
at org.mariadb.jdbc.MariaDbClientPreparedStatement.executeInternal(MariaDbClientPreparedStatement.java:233)
at org.mariadb.jdbc.MariaDbClientPreparedStatement.executeQuery(MariaDbClientPreparedStatement.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
at com.sun.proxy.$Proxy81.executeQuery(Unknown Source)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 80 more
Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Table 'crm_application.MenuPrivileges' doesn't exist
Query is: select ur.role_id ,ur.role_name ,ur.speciality ,ms.section_id ,ms.section_name ,ms.section_position ,ms.section_icon ,mi.menu_id ,mi.menu_name ,mi.menu_action ,mi.menu_position ,mi.parent_menu_id from MenuPrivileges mp inner join UserRoles ur on mp.role_id = ur.role_id inner join MenuItems mi on mp.menu_id = mi.menu_id inner join MenuSections ms on mi.section_id = ms.section_id where mi.active_ind = '1' and mp.visible_ind = '1' and mp.role_id = (select role_id from crm_users where user_id = ?) order by ms.section_position asc, parameters [3]
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readErrorPacket(AbstractQueryProtocol.java:1144)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1076)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1031)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:203)
at org.mariadb.jdbc.MariaDbClientPreparedStatement.executeInternal(MariaDbClientPreparedStatement.java:224)
... 88 more
2017-11-07 10:27:47.383 ERROR 3116 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
答案 0 :(得分:0)
在getMenusByRole
中,您使用的是纯SQL,而不是HSQL。因此,您的表格名称应为crm_menu_privileges
,crm_user_roles
等等。
答案 1 :(得分:0)
在使用本机查询时,getResultSet()方法不会返回User类的对象。另一个原因是在此查询中未调用HQL,它将无法通过自己映射实体。
在您的情况下,getResultSet()将返回Object数组,如下所示:
List<Object[]> l = q.getResultList();
然后你必须从这个返回的数组中提取每个元素。
例如,Object [0]将返回ur.role_id,Object [1]将返回ur.role_name,依此类推查询。