-->
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.  [ 5 posts ] 
Author Message
 Post subject: java.lang.IllegalStateException: No data type for node
PostPosted: Tue May 10, 2005 1:06 pm 
Newbie

Joined: Tue May 10, 2005 11:53 am
Posts: 4
The error I get when trying to retrieve information from the database is:

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.IdentNode
\-[IDENT] IdentNode: 'c' {originalText=c}

This seems to be coming from the line of code (in the .jsp)
Query query = hibSession.createQuery( "SELECT c FROM Dogs AS c WHERE c.sex = :sex" );

Note, I'm using the Chapter 1 - Quickstart with Tomcat as a basis for my tests. (I am a dog person so I replaced Dog everywhere I saw Cat. hehe)

Thanks.

Pertinent Info: (I think)

Hibernate version:
3

Mapping documents:
<?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="connection.datasource">java:comp/env/jdbc/dogrunDB</property>
<property name="show_sql">false</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="Dog.hbm.xml"/>

</session-factory>

</hibernate-configuration>

AND

<?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.tosg.core.model.Dog" table="Dogs">

<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="dogID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="name">
<column name="name" length="20" not-null="true"/>
</property>

<property name="sex"/>

<property name="weight"/>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Note: this is in a jsp page SIMPLY for ease in debugging. it will be all properly implemented into my struts app once I get it working.

<%
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "SELECT c FROM Dogs AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
%>
Name: <%= dog.getName() %><BR>

<%
}
tx.commit();
HibernateUtil.closeSession();
%>

Full stack trace of any exception that occurs:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.IdentNode
\-[IDENT] IdentNode: 'c' {originalText=c}

org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(SelectClause.java:138)
org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:440)
org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:351)
org.hibernate.hql.antlr.HqlSqlBaseWalker.afterQuery(HqlSqlBaseWalker.java:126)
org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:471)
org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:422)
org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:822)
org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:858)
org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
org.apache.jsp.jsp.index_jsp._jspService(index_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Name and version of the database you are using:
Mysql 4.0.17-NT

The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 1:15 pm 
Newbie

Joined: Tue May 10, 2005 11:53 am
Posts: 4
I should mention that I am able to ADD / UPDATE information in the database but I just cannot SELECT it.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 1:25 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Hibernate querying works with entity names, not with database table name.

Replace
Code:
Query query = hibSession.createQuery( "SELECT c FROM Dogs AS c WHERE c.sex = :sex" );


by

Code:
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + "  AS c WHERE c.sex = :sex" );


or the equivalent:

Code:
Query query = hibSession.createQuery( "FROM com.tosg.core.model.Dog  AS c WHERE c.sex = :sex" );


It will work

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 1:50 pm 
Newbie

Joined: Tue May 10, 2005 11:53 am
Posts: 4
Hi

Worked like a charm.. thanks.

Now the thing about all this is I copy/pasted the code from the Hibernate Quickstart guide.

http://www.hibernate.org/hib_docs/v3/re ... start.html

Right near the bottom....

This should be fixed by whoever maintains the docs.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 2:07 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
You are right, the example is misleading.

They should put the package name on Cat to make sure that we are talking about the entity and not about the table.

If you want to notify the hibernate team about this, I believe the proper way is by requesting an enhancement at:

http://opensource.atlassian.com/project ... board.jspa

The documentation section is found here: http://opensource.atlassian.com/project ... nent=10045


:)

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.