Native SQL throwing Invalid Column Name Exception

前端 未结 3 2026
借酒劲吻你
借酒劲吻你 2021-01-12 01:31

I am using Hibernate 3.2.5 for my application.

I have a Dept table and an Employees table.

Dept.java



        
相关标签:
3条回答
  • 2021-01-12 02:01

    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)
    
    0 讨论(0)
  • 2021-01-12 02:15

    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")
    
    0 讨论(0)
  • 2021-01-12 02:16

    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.

    0 讨论(0)
提交回复
热议问题