I was trying to use a native query and got the following exception.
Hibernate: SELECT DP.DOCUMENT_PACKAGE_ID, DP.DOCUMENT_SIGNED_DATE, DP.DOCUMENT_SIGNED_IND,
DC.DOCUMENT_PACKAGE_ID, DC.DOB, DC.FIRST_NAME, DC.GENDER, DC.LAST_NAME, DC.MIDDLE_NAME, DC.SSN
FROM DOCUMENT_PACKAGE DP
LEFT OUTER JOIN DOCUMENT_CLIENT DC ON (DP.DOCUMENT_PACKAGE_ID = DC.DOCUMENT_PACKAGE_ID)
WHERE DP.DOCUMENT_PACKAGE_ID = ?
WARN [org.hibernate.util.JDBCExceptionReporter] - <SQL Error: 17006, SQLState: null>
ERROR [org.hibernate.util.JDBCExceptionReporter] - <Invalid column name>
ERROR [sample.maxie.dao.DocumentPackageDAO] - <get failed>
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at sample.maxie.dao.DocumentPackageDAO.getDocumentPackageWithClient(DocumentPackageDAO.java:94)
at sample.maxie.utils.Runner.documentPackageWithClient(Runner.java:71)
at sample.maxie.utils.Runner.main(Runner.java:88)
Caused by: java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3287)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1575)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 7 more
The named query that I used for this is
Code:
<sql-query name="documentPackageWithClient">
<return alias="DP" class="sample.maxie.pojos.DocumentPackage"/>
<return alias="DC" class="sample.maxie.pojos.DocumentClient"/>
<![CDATA[SELECT {DP}.DOCUMENT_PACKAGE_ID, {DP}.DOCUMENT_SIGNED_DATE, {DP}.DOCUMENT_SIGNED_IND,
{DC}.DOCUMENT_PACKAGE_ID, {DC}.DOB, {DC}.FIRST_NAME, {DC}.GENDER, {DC}.LAST_NAME, {DC}.MIDDLE_NAME, {DC}.SSN
FROM DOCUMENT_PACKAGE {DP}
LEFT OUTER JOIN DOCUMENT_CLIENT {DC} ON ({DP}.DOCUMENT_PACKAGE_ID = {DC}.DOCUMENT_PACKAGE_ID)
WHERE {DP}.DOCUMENT_PACKAGE_ID = :paramDocumentPackageId]]>
</sql-query>
and the Java code isCode:
public DocumentPackage getDocumentPackageWithClient(java.lang.Long id)
{
DocumentPackage retval = null;
try
{
Query query = getSession().getNamedQuery("documentPackageWithClient");
query.setParameter("paramDocumentPackageId", id);
List buffer = query.list();
retval = ((buffer != null) && (buffer.size() > 0)) ? (DocumentPackage) buffer.get(0) : null;
}
catch (RuntimeException re)
{
log.error("get failed", re);
throw re;
}
return(retval);
}