Native SQL throwing Invalid Column Name Exception

浪尽此生 提交于 2019-12-01 03:42:57

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")
Gordon Ma

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)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!