gpt4 book ai didi

java - org.hibernate.hql.ast.QuerySyntaxException : Employee_detail is not mapped [from Employee_detail]

转载 作者:行者123 更新时间:2023-12-01 11:33:10 26 4
gpt4 key购买 nike

我的sql查询是select * from employee_detail;

错误是:-

SEVERE: Servlet.service() for servlet [spring] in context with path [/Roster_APP] threw exception [Request processing failed; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Employee_detail is not mapped [from Employee_detail]] with root cause
org.hibernate.hql.ast.QuerySyntaxException: Employee_detail is not mapped [from Employee_detail]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.lak.dao.impl.EmployeeDaoImpl.getAllEmployee(EmployeeDaoImpl.java:45)
at com.lak.service.impl.EmployeeServiceImpl.getAllEmployee(EmployeeServiceImpl.java:44)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy24.getAllEmployee(Unknown Source)
at com.lak.controller.EmployeeContoller.getAllEmployee(EmployeeContoller.java:44)
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.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
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)

Controller 是:

@Controller
public class EmployeeContoller {
@Autowired
private EmployeeServices employeeServices;

@RequestMapping("/index")
public String setupForm(Map<String,Object>map){

Employee employee=new Employee();
map.put("employee", employee);
map.put("employee_List", employeeServices.getAllEmployee());
return "employee";

}



@RequestMapping(value = "/employeeList", method = RequestMethod.GET)
public @ResponseBody ArrayList<Employee> getAllEmployee() {



System.out.println("-------------- inside getUsers() ...");

ArrayList<Employee> employee_List = (ArrayList<Employee>) employeeServices.getAllEmployee();

return employee_List;

}



}

dao 文件是:

public interface EmployeeDao {
public void add(Employee employee);
public void edit(Employee employee);
public void delete(String empNumer);
public Employee getEmployee(String empNumer);
public List getAllEmployee();

}

daoimpl.java 是

@Repository

public class EmployeeDaoImpl implements EmployeeDao {

@Autowired
private SessionFactory session;

@Override
public void add(Employee employee) {

session.getCurrentSession().save(employee);

}

@Override
public void edit(Employee employee) {
session.getCurrentSession().update(employee);

}

@Override
public void delete(String empNumer) {
session.getCurrentSession().delete(getEmployee(empNumer));

}

@Override
public Employee getEmployee(String empNumer) {
return (Employee)session.getCurrentSession().get(Employee.class, empNumer);
}

@Override
public List getAllEmployee() {
return session.getCurrentSession().createQuery("from employee_detail").list();
}


}

hibernate.cfg.xml 是:-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

<!-- Assume hibernateTutorial is the database name -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/roster_app</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.current_session_context_class"> org.springframework.orm.hibernate3.SpringSessionContext
</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.idle_test_period">3600</property>
<property name="hibernate.c3p0.timeout">28800</property>
<mapping class="com.lak.model.Employee" />

</session-factory>
</hibernate-configuration>

如何解决这个问题?

最佳答案

M。 Deinum 的评论是正确的。您需要使用 HQL。没有看到你的 ORM 模型,但根据 hibernate.cfg.xml 判断,你有一个名为 Employee 的 ORM 类,这让我相信 Employee_detail 是数据库中 Employee 表内的一列。它是否正确?如果是这样,您想要的是类似于以下内容的 HQL 查询:

从员工中选择员工详细信息

这将为您提供employee_detail列的结果。如果您只想要 Employee 对象的列表,那么您希望查询如下:

来自员工

这将为您提供 Employee 对象的列表,每个对象都有自己的字段,用于数据库表中的任何列。看看这个方法:

@Override
public List getAllEmployee() {
return session.getCurrentSession().createQuery("from Employee").list();
}

关于java - org.hibernate.hql.ast.QuerySyntaxException : Employee_detail is not mapped [from Employee_detail],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30262457/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com