前提・実現したいこと
ページを表示させたいのですが、表示されずエラーとなってしまいます。
発生している問題・エラーメッセージ
例外 javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149) org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157) org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1423) org.hibernate.query.Query.getResultList(Query.java:146) controllers.employees.EmployeeIndexServlet.doGet(EmployeeIndexServlet.java:43) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) filters.EncodingFilter.doFilter(EncodingFilter.java:42) 原因 org.hibernate.exception.SQLGrammarException: could not extract ResultSet org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111) org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69) org.hibernate.loader.Loader.getResultSet(Loader.java:2168) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1931) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) org.hibernate.loader.Loader.doQuery(Loader.java:938) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) org.hibernate.loader.Loader.doList(Loader.java:2692) org.hibernate.loader.Loader.doList(Loader.java:2675) org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) org.hibernate.loader.Loader.list(Loader.java:2502) org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:392) org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490) org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445) org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) org.hibernate.query.Query.getResultList(Query.java:146) controllers.employees.EmployeeIndexServlet.doGet(EmployeeIndexServlet.java:43) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) filters.EncodingFilter.doFilter(EncodingFilter.java:42) 原因 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'employee0_.admin_flg' in 'field list' sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) java.lang.reflect.Constructor.newInstance(Constructor.java:423) com.mysql.jdbc.Util.handleNewInstance(Util.java:425) com.mysql.jdbc.Util.getInstance(Util.java:408) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484) com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60) org.hibernate.loader.Loader.getResultSet(Loader.java:2168) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1931) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) org.hibernate.loader.Loader.doQuery(Loader.java:938) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) org.hibernate.loader.Loader.doList(Loader.java:2692) org.hibernate.loader.Loader.doList(Loader.java:2675) org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) org.hibernate.loader.Loader.list(Loader.java:2502) org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:392) org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490) org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445) org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) org.hibernate.query.Query.getResultList(Query.java:146) controllers.employees.EmployeeIndexServlet.doGet(EmployeeIndexServlet.java:43) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) filters.EncodingFilter.doFilter(EncodingFilter.java:42)
該当のソースコード
List<Employee> employees = em.createNamedQuery("getAllEmployees", Employee.class).setFirstResult(15 * (page - 1)).setMaxResults(15).getResultList();
@WebServlet("/employees/index") public class EmployeeIndexServlet extends HttpServlet { private static final long serialVersionUID = 1L; public EmployeeIndexServlet() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = DBUtil.createEntityManager(); int page = 1; try{ page = Integer.parseInt(request.getParameter("page")); } catch(NumberFormatException e) {} List<Employee> employees = em.createNamedQuery("getAllEmployees", Employee.class).setFirstResult(15 * (page - 1)).setMaxResults(15).getResultList(); long employees_count = (long)em.createNamedQuery("getEmployeesCount", Long.class).getSingleResult(); em.close(); request.setAttribute("employees", employees); request.setAttribute("employees_count", employees_count); request.setAttribute("page", page); if(request.getSession().getAttribute("flush") != null){ request.setAttribute("flush", request.getSession().getAttribute("flush")); request.getSession().removeAttribute("flush"); } RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/employees/index.jsp"); rd.forward(request, response); } }
試したこと
おそらくここだと思います。。。
補足情報(FW/ツールのバージョンなど)
(追記)
Java8, Hibernate5, Tomcat8
回答1件
あなたの回答
tips
プレビュー