0

Currently trying to get some simple transactions going between Hibernate and our database. I keep running into the following error:

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

I checked my spelling of types and verified my issue here. Unfortunately I have been unable to spot the problem.

The DAO:

    @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;
        }

    }

The Entity:

    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;
        }
    }

And finally, the 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;
        }
    }

All names are constant. The Employee type is clearly mapped to the Employee table, yet Hibernate says that it is not. What is going on here?

SternK
  • 11,649
  • 22
  • 32
  • 46
Matthew
  • 817
  • 1
  • 13
  • 39
  • I think you need to tell hibernate that the class exists in the persistence.xml aswell or orm.xml / some other config file – Mark Feb 20 '20 at 20:43
  • Not overly descriptive there mark... any ideas? I haven't had this issue with Hibernate before. – Matthew Feb 20 '20 at 21:35
  • @Matthew check if you are using some HBM mappings that override the annotations Or the annotated entities were not scanned by Hibernate. – Mayank Tripathi Feb 21 '20 at 04:25
  • Please add your persistence.xml to the question – Smutje Feb 21 '20 at 10:57

0 Answers0