The "invalid column name" error message is misleading when the real problem is
that there is a bean field that doesn't have a matching column name in the query.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-6721
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6721
Project: Hibernate Core
Issue Type: Improvement
Components: query-sql
Environment: hibernate-core 3.6.6.Final. Oracle database.
Reporter: HappyEngineer
Priority: Minor
If I have the following bean:
@Entity
public class Foobar
{
@Id
private int id;
private String name;
}
and the following unit tests:
@PersistenceContext(unitName = "reports2") private EntityManager em;
@Test
public void testGoodColumnName() {
em.createNativeQuery("select 1 id, 'name' name from
dual",Foobar.class)
.getResultList();
}
@Test
public void testBadColumnName() {
em.createNativeQuery("select 1 id, 'name' name2 from
dual",Foobar.class)
.getResultList();
}
the first unit test will succeed, but the second will fail with an "Invalid column
name" SQLException.
The reason for this is that the "name" field in the class doesn't have a
corresponding "name" column in the query.
Because I'm using Oracle I'm used to getting error messages which are unhelpful
because they don't mention the column name that is invalid when I write an invalid
query. As a result I spent a lot of time trying to figure out why the query worked when
run in Squirrel SQL but not when run with Hibernate. Of course, I eventually figured out
that the problem was the one I outlined above.
It would have been much simpler for me if the error message had simply said something like
"The query does not specify a column which corresponds to the 'name' field of
bean com.foo.Foobar.".
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira