I am using JPA and java as technology and writing very simple web application. There is one class called Employee, look like below code
@Entity
@Table(name="Employee")
public class Employee{
@Id
private int id;
@Column(name="name")
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
one table called Employee is exist into database. Its persistence.xml file looks like below code.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="JPAService" transaction-type="RESOURCE_LOCAL">
<!-- Persistence provider -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- Entity classes -->
<class>com.solution.domain.Employee</class>
<properties>
<!-- The JDBC driver of your database -->
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<!-- The JDBC URL to the database instance -->
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/test" />
<!-- The database username -->
<property name="javax.persistence.jdbc.user" value="postgres" />
<!-- The database password -->
<property name="javax.persistence.jdbc.password" value="postgres"/>
<property name="javax.persistence.jdbc.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
</properties>
</persistence-unit>
</persistence>
Employee class entry exist in this xml file.
There are not issue while startup of application. Every thing working fine.
But when query is executed then it throw and exception.
"Employee is not mapped [select e from Employee e]"
EntityManager em = getEntityManager();
em.getTransaction().begin();
Query query = em.createQuery("select e from Employee e");
List<Employee> employees = query.getResultList();
if(employees != null){
return employees.get(0);
}
em.getTransaction().commit();
I am unable to understand where mapping is missing. As i already mentioned its a web project. So for more clarification i am attaching one screen shot of my project too.
Thanks in advance.