-->
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.  [ 2 posts ] 
Author Message
 Post subject: IllegalStateException
PostPosted: Tue Jun 26, 2007 8:50 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.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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 1:55 am 
Beginner
Beginner

Joined: Mon Apr 23, 2007 8:30 am
Posts: 27
Location: India
Look at the query carefully. You are using a mix of column names and mapped class name. There are column names in the select clause and the mapped class in the from clause.

Replace the from clause to have the tablename "people" or use mapped java fields in the select clause.

Hope this helps!

Nikhil


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.