Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2.4
Mapping documents:
<?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="com.javarunner.server.db.PeopleToo"
table="people"
dynamic-update="false"
dynamic-insert="false">
<id column="id"
name="Id"
type="java.lang.Integer">
<!-- <generator class="native"/> -->
</id>
<property column="first_name" type="java.lang.String" length="255"
not-null="true" name="firstName" />
<property column="last_name" length="255"
not-null="true" name="lastName" type="java.lang.String" />
<property column="sex" length="255"
not-null="true" name="sex" type="java.lang.String" />
<property column="age" length="5"
not-null="true" name="age" type="java.lang.Integer" />
<property column="race" length="5"
not-null="true" name="race" type="java.lang.Integer" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session session = factory.openSession();
List<PeopleToo> people = service.getAllPeople(session);
if (people != null && people.size() > 0) {
Iterator it = people.iterator();
while (it.hasNext()) {
person = (PeopleToo)it.next();
System.out.println("First Name: " + person.getFirstName() +
" Last Name: " + person.getLastName() +
" Age: " + person.getAge());
}
} else {
System.out.println("No results returned!");
}
}
public List getAllPeople(Session session) {
Query query = null;
List result = null;
try {
query = session.createQuery("SELECT first_name, last_name, age, sex FROM PeopleToo");
if (query != null) result = query.list();
}
catch (HibernateException he) {
System.out.println("HE: " + he.getMessage());
he.printStackTrace();
}
finally {
if (session != null)
session.close();
}
return result;
}
Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode
+-[IDENT] IdentNode: 'first_name' {originalText=first_name}
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:145)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:705)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:529)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.javarunner.server.db.TypicalDBService.getAllPeople(TypicalDBService.java:41)
at com.javarunner.server.db.TypicalDBService.main(TypicalDBService.java:23)
Name and version of the database you are using:
mySQL 5.0.15
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html