Hi all,
I am stuck with this since a very long time. I am getting this error for an HQL or a native sql query in hibernate. I
request you to help me. I am unable to find the post where this has been discussed before. Kindly help!
Error
Code:
INFO: Not binding factory to JNDI, no JNDI name configured
Aug 14, 2009 7:04:57 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
Hibernate: select user0_.USERNAME from USER user0_
Aug 14, 2009 7:04:58 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: S0022
Aug 14, 2009 7:04:58 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column 'col_0_0_' not found.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at
org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1518)
at org.hibernate.loader.Loader.list(Loader.java:1498)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:266)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:788)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at myapp.test.dao.HibernateDAO.validatePassword(HibernateDAO.java:41)
at myapp.test.dao.HibernateDAO.main(HibernateDAO.java:468)
Caused by: java.sql.SQLException: Column 'col_0_0_' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:970)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5613)
at org.hibernate.type.StringType.get(StringType.java:16)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.loader.hql.QueryLoader.getResultColumnOrRow(QueryLoader.java:320)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:313)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.doList(Loader.java:1515)
... 7 more
Code
Code:
public User validatePassword(String username, String password){
String QUERY = "select username from User";
Query query = session.createQuery(QUERY);
session = HibernateInitializer.getSession();
List<Object[]> data = (List<Object[]>)query.list();
Iterator<Object[]> it = data.iterator();
User user = null;
try {
while(it.hasNext()) {
Object[] row = (Object[]) it.next();
user = new User();
user.setUsername((String)row[0]);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
session.flush();
session.close();
}
return user;
}
xml files
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="user.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="User" table="USER">
<id name="username" column="USERNAME">
</id>
</class>
</hibernate-mapping>