I am using Hibernate 3.2.5 for my application.
I have a Dept
table and an Employees
table.
Dept.java
I had the same issue.
The reason is my column name in annotation is not correct.
@Column(name = "CUSTOMER_NAME", length = 200)
should be changed to
@Column(name = "CUST_NM", length = 200)
you have this in your mapping:
<column name="DEPT_NAME"></column>
but there is no such column in your sql between Select
and from
:
session.createSQLQuery("Select d.DEPT_ID, e.EMP_NAME from Dept d,Emp e where d.DEPT_ID = e.DEPT_ID")
Hibernate has no possibilitys to bind the attribute. Try it with this:
session.createSQLQuery("Select d.DEPT_ID, d.DEPT_NAME, e.EMP_NAME from Dept d,Emp e where d.DEPT_ID = e.DEPT_ID")
Here are my 2cents in addition to what Stefan Beike.
In your case, the table is small. But if you are writing a similar query for a large table, and if you don't want the entire columns to be fetched into the memory, writing a new DataTransferObject to use as your resultset-ref would be ideal.