I modified code from chapter 2 of the Java Persistence book. I have been able to get this same code to insert new records but I cannot get it to read from the table. I am doing this within a servlet. I originally recieved a message that it could not find the mapping file, but I fixed that by copying the file to the classes directory.
Anyone see what I am missing?
Here is the DDL:
Code:
create table EMPLOYEE
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
employee varchar(100),
lastChanged TIMESTAMP
);
Here is the mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.paramountProfressional.Employee"
table="EMPLOYEE">
<id
name="id"
column="id">
<generator class="native"/>
</id>
<property
name="employee"
column="employee"/>
<property
name="lastChanged"
column="lastChanged"/>
</class>
</hibernate-mapping>
Here is the bean
Code:
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "EMPLOYEE")
public class Employee {
private int id;
private String employee;
private Date lastChanged;
public Employee(){}
public Employee(String empl){}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEmployee() {
return employee;
}
public void setEmployee(String employee) {
this.employee = employee;
}
public Date getLastChanged() {
return lastChanged;
}
public void setLastChanged(Date lastChanged) {
this.lastChanged = lastChanged;
}
}
Here is the code withing the servlet.
Code:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Session session = HibernateUtil.getSessionFactory().openSession();
Statistics stats = HibernateUtil.getSessionFactory().getStatistics();
List list = session.createQuery("from EMPLOYEE m ").list();
session.close();
}
Here is the stacktrace
Code:
Oct 1, 2009 1:10:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet TestServlet threw exception
org.hibernate.hql.ast.QuerySyntaxException: EMPLOYEE is not mapped [from EMPLOYEE m ]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)