有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Hibernate无法映射到表?

目前正在尝试在Hibernate和我们的数据库之间进行一些简单的事务。我一直遇到以下错误:

path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped [from Employee]] with root cause

我检查了类型的拼写,并验证了我的问题here。不幸的是,我一直无法发现这个问题

道:

    @Service
    public class EmployeeDaoImplementation implements EmployeeDao {

        @Override
        public List<Employee> findall() {

            Session currentSession = Statics.getSessionFactory().getCurrentSession();

            if(currentSession == null)
                currentSession = Statics.getSessionFactory().openSession();

            currentSession.beginTransaction();

            Query<Employee> theQuery = currentSession.
                    createQuery("from Employee", Employee.class);

            List<Employee> employeeList = theQuery.getResultList();

            currentSession.close();
            return employeeList;
        }

    }

实体:

    package com.ots;

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;

    @Entity
    @Table(name="Employee")
    public class Employee {

        @Id
        @Column
        private int id;

        @Column
        private String fName;

        @Column
        private String lName;

        public Employee() {

        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getfName() {
            return fName;
        }

        public void setfName(String fName) {
            this.fName = fName;
        }

        public String getlName() {
            return lName;
        }

        public void setlName(String lName) {
            this.lName = lName;
        }
    }

最后,RestController:

    @RestController
    public class EmployeeRestController {

        private EmployeeDao empDao;

        @GetMapping("/list")
        public List<Employee> getEmployees(){

            return empDao.findall();
        }

        @Autowired
        public void setEmployeeDaoImplementation(EmployeeDao empDao) {

            this.empDao = empDao;
        }
    }

所有的名字都是不变的。Employee类型清楚地映射到Employee表,但Hibernate说不是这样。这是怎么回事


共 (0) 个答案