I have the following method in my Java application's DAO layer:
public void save(Employee emp) {
System.out.println("emp type: " + emp.getClass().getName);
getHibernateTemplate().save(emp);
System.out.println("object saved!");
System.out.flush();
}
The employee class does not extend from any other classes and has the following hbm file:
<hibernate-mapping>
<class name="org.myCompany.Employee" table="employee">
<!-- fields omitted to save space -->
</hibernate-mapping>
Yet the insert fails with a java.lang.ClassCastException. At first, I thought something was wrong with my mapping (like an Integer mapping to a boolean) but then I turned on hibernate's show_sql debugging and found the following in my log file:
emp type: org.myCompany.Employee
Hibernate: insert into customer (.......) values (......)
java.lang.ClassCastException
Why did it pick an entirely random table to insert into? I'm sure that I must have some config file mis-configured, but I don't know which one. I checked the following:
- applicationContext-hibernate.xml -> both the Customer and Employee objects are mapped to their correct hbm files
- neither Customer or Employee have an inheritance relationship (there isn't even a common parent class like Person or User)
What else could I try?