2.1.6
MySQL 4.0.20a
Ok, this post is going to be a bit long because of all the mappings and code I must display so I can get help with my problem. Brief rundown...I have a User class and an Employee class. I have mappings for both files. I also have UserDAO and an EmployeeDAO classes. Both of which currently just have get methods (getUser...getEmployee). I am working on a web application and I am using the UserDAO for when a user logs into the site. This works fine. I also have an Employee Search feature. For all intent and purposes, it is exactly like the user methods but searches a different table. And I am getting a very odd error. Ok, here are all my classes and mappings. After which I will post the error message when doing the employee search...
[User.java]
Code:
public class User extends Employee implements HttpSessionBindingListener
{
private Long userId;
private String password;
private String firstName;
private String lastName;
private String role;
private Integer status;
private Date lastLoggedIn;
private String email;
public Long getUserId()
{
return userId;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
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 getRole()
{
return role;
}
public void setRole(String role)
{
this.role = role;
}
public Integer getStatus()
{
return status;
}
public void setStatus(Integer status)
{
this.status = status;
}
public Date getLastLoggedIn()
{
return lastLoggedIn;
}
public void setLastLoggedIn(Date lastLoggedIn)
{
this.lastLoggedIn = lastLoggedIn;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
}
[User.xml]
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.intrust.anykey.beans.User" table="user_table">
<id name="userId" column="user_id" type="long">
<generator class="assigned"/>
</id>
<property name="password" column="password" type="string"/>
<property name="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
<property name="role" column="role" type="string"/>
<property name="status" column="status" type="int"/>
<property name="lastLoggedIn" column="last_logged_in" type="date"/>
<property name="email" column="email" type="string"/>
</class>
</hibernate-mapping>
[UserDAO.java]
Code:
public class UserDAO
{
public UserDAO()
{
HibernateUtil.beginTransaction();
}
public User getUser(Long userId, String password)
{
User user = null;
try
{
Session session = HibernateUtil.getSession();
Criteria crit = session.createCriteria(User.class);
crit.add( Expression.eq("userId", userId) );
crit.add( Expression.eq("password", password) );
List result = crit.list();
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
if (!result.isEmpty())
{
user = (User)result.get(0);
}
return user;
}
catch(HibernateException hx)
{
hx.printStackTrace(System.out);
user = null;
return user;
}
}
}
[Employee.java]
Code:
public class Employee
{
private Long empId;
private String firstName;
private String lastName;
private String department;
private String phone;
private String mailStop;
private String email;
public Long getEmpId()
{
return empId;
}
public void setEmpId(Long empId)
{
this.empId = empId;
}
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 getDepartment()
{
return department;
}
public void setDepartment(String department)
{
this.department = department;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getMailStop()
{
return mailStop;
}
public void setMailStop(String mailStop)
{
this.mailStop = mailStop;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
}
[EmployeeDAO.java]
Code:
public class EmployeeDAO
{
public EmployeeDAO()
{
HibernateUtil.beginTransaction();
}
public Employee getEmployee(Long id)
{
Employee emp = null;
try
{
Session session = HibernateUtil.getSession();
Criteria crit = session.createCriteria(Employee.class);
crit.add( Expression.eq("empId", id) );
List result = crit.list();
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
if (!result.isEmpty())
{
System.out.println("Found an employee");
emp = (Employee)result.get(0);
}
else
{
System.out.println("Could not find employee");
}
return emp;
}
catch(HibernateException hx)
{
emp = null;
hx.printStackTrace(System.out);
return emp;
}
}
}
[Employee.xml]
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.intrust.anykey.beans.Employee" table="employee_table">
<id name="empId" column="emp_id" type="long">
<generator class="assigned"/>
</id>
<property name="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
<property name="department" column="department" type="string"/>
<property name="phone" column="phone" type="string"/>
<property name="mailStop" column="mail_stop" type="string"/>
<property name="email" column="email" type="string"/>
</class>
</hibernate-mapping>
[HibernateUtil.java]
Code:
public class HibernateUtil
{
private static final SessionFactory sessionFactory;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
static
{
try
{
Configuration cfg = new Configuration();
sessionFactory = cfg.configure().buildSessionFactory();
}
catch (Throwable ex)
{
ex.printStackTrace(System.out);
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException
{
Session s = (Session)threadSession.get();
try
{
if (s == null)
{
s = sessionFactory.openSession();
threadSession.set(s);
}
}
catch(HibernateException he)
{
he.printStackTrace(System.out);
}
return s;
}
public static void closeSession()
{
try
{
Session s = (Session)threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen())
{
s.close();
}
}
catch(HibernateException hx)
{
hx.printStackTrace(System.out);
}
}
public static void beginTransaction()
{
Transaction tx = (Transaction)threadTransaction.get();
try
{
if (tx == null)
{
tx = getSession().beginTransaction();
threadTransaction.set(tx);
}
}
catch(HibernateException hx)
{
hx.printStackTrace(System.out);
}
}
public static void commitTransaction()
{
Transaction tx = (Transaction)threadTransaction.get();
try
{
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack())
{
tx.commit();
threadTransaction.set(null);
}
}
catch(HibernateException hx)
{
rollbackTransaction();
hx.printStackTrace(System.out);
}
}
public static void rollbackTransaction()
{
Transaction tx = (Transaction)threadTransaction.get();
try
{
threadTransaction.set(null);
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack())
{
tx.rollback();
}
}
catch(HibernateException hx)
{
hx.printStackTrace(System.out);
}
finally
{
closeSession();
}
}
}
The exception I get when I call the EmployeeDAO.getEmployee method is:
Code:
net.sf.hibernate.QueryException: could not resolve property: empId of: com.intrust.anykey.beans.User
This happens before any SQL is submitted. I have no idea why it still thinks it is looking at the User object for empId. Any ideas?