I am trying to get a list of employees from the database I had used spring boot and hibernate for doing this project. According to me, I had done everything right but I am getting this ugly exception
org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped [from Employee];
I had nearly tried all the solution which are on internet some guys suggested that POJO name and name used in query must be same and i had done that also.
@Entity
@Table(name="employee")
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@Column(name="email")
private String email;
public Employee() {
}
public Employee(String firstName, String lastName, String email) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Employee [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";
}
}
@Repository
public class EmployeeDaoImpl implements EmployeeDao {
@Autowired
private EntityManager entity;
@Override
@Transactional
public List<Employee> ListAllEmployee() {
//create Session
Session session=entity.unwrap(Session.class);
Query<Employee> employee=session.createQuery("from Employee",Employee.class);
return employee.getResultList();
}
}