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?