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.People"
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" length="255"
not-null="true" name="firstName" type="java.lang.String" />
<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>
[b]Code between sessionFactory.openSession() and session.close():
Session session = factory.openSession();
List<People> people = service.getAllPeople(session);
if (people != null && people.size() > 0) {
Iterator it = people.iterator();
while (it.hasNext()) {
person = (People)it.next();
System.out.println("First Name: " + person.getFirstName() +
" Last Name: " + person.getLastName() +
" Age: " + person.getAge());
}
}
}
public List getAllPeople(Session session) throws HibernateException {
Query query = null;
try {
query = session.createQuery("from people AS people");
}
finally {
if (session != null)
session.close();
}
return query.list();
}
Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: people is not mapped [from people AS people]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
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:46)
at com.javarunner.server.db.TypicalDBService.main(TypicalDBService.java:32)
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