-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem with mappings
PostPosted: Tue Jun 26, 2007 3:36 pm 
Newbie

Joined: Fri Apr 28, 2006 9:42 am
Posts: 9
Location: Florida, USA
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 3:41 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Quote:
query = session.createQuery("from people AS people");


should be:
Code:
query = session.createQuery("from People AS people");


The word after from should be the class name.

*Don't forget to rate*

Regards,
Jitendra


Top
 Profile  
 
 Post subject: thanks
PostPosted: Tue Jun 26, 2007 4:28 pm 
Newbie

Joined: Fri Apr 28, 2006 9:42 am
Posts: 9
Location: Florida, USA
Just a 'slip of the case'! Thanks...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.