-->
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: Hibernate Error java.lang.IllegalStateException
PostPosted: Thu Sep 04, 2008 2:07 pm 
Newbie

Joined: Wed Sep 03, 2008 5:18 pm
Posts: 1
I am getting the following error whaen i run Simple Query.I am using DB2 dialect...

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.IdentNode
\-[ALIAS_REF] IdentNode: 'FINANCE_NBR' {alias=FINANCE_NBR, no from element}

at org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(SelectClause.java:122)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:414)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:355)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.afterQuery(HqlSqlBaseWalker.java:119)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:456)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:184)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:140)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at gov.usps.dpr.batch.hibernate.JavaSource.SelectClauseExample.main(SelectClauseExample.java:37)



My hbm File

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="gov.usps.dpr.batch.hibernate.JavaSource">
<class name="DlvryFac" table="DLVRY_FAC"
>


<meta attribute="sync-DAO">false</meta>

<id column="id" name="id" type="java.lang.Long" unsaved- value="null">
<generator class="native" />
</id>

<property
name="FinanceNbr"
column="FINANCE_NBR"
type="string"
not-null="true"
length="6"
/>


</class>
</hibernate-mapping>



My Bean Java Code

package gov.usps.dpr.batch.hibernate.JavaSource;


public class DlvryFac {
private String FinanceNbr;

private String id;



public String getFinanceNbr() {
return FinanceNbr;
}

public void setFinanceNbr(String financeNbr) {
FinanceNbr = financeNbr;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}



}


My Example File

public class SelectClauseExample {
public static void main(String[] args) {
Session session = null;

try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();


//Create Select Clause HQL
// String SQL_QUERY =" Select " +
// " FIN_NBR_BUD_HRS, " +
// " FIN_NBR_BUD_POSDEL, " +
// " FIN_NBR_BUD_VOL " +
// " from " + " Contact";

String SQL_QUERY = " SELECT DISTINCT FINANCE_NBR FROM DOIS01T.DLVRY_FAC WHERE DISTRICT_ID <>''";

Query query = session.createQuery(SQL_QUERY);

List lst=query.list();

for(Iterator it=query.iterate();it.hasNext();){

DlvryFac contact = new DlvryFac();
//contact.getId();
contact.getFinanceNbr();
contact.getId();
session.save(contact);
System.out.println("Done");
System.out.println("ID: " + contact.getId());
System.out.println("Name: " + contact.getFinanceNbr());
}

session.close();
}catch(Exception e){

e.printStackTrace();

}finally{
}
}
}


Can Any one help Please.......


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 2:57 pm 
Beginner
Beginner

Joined: Wed Apr 20, 2005 9:30 am
Posts: 39
Do you have a mapping file for FINANCE_NBR?

Looks like you're doing a query against something that isn't mapped? Also, and I don't know much about DB2 but isn't that query missing a parameter? As in
Code:
select distinct thing as t where t.district <> someDistrict
or put in a more HQL-ish way:
Code:
select distinct thing as t where t.district <> ?
Where the '?' would be set in the Hibernate Query object before it is executed (q.list()).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 4:38 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The Session.createQuery() expects a HQL query, not SQL query. Use Session.createSQLQuery() instead or (better) convert your query to HQL. Something like:

Code:
SELECT DISTINCT df.FinanceNbr FROM DlvryFac df WHERE df.id <>''"


One strange thing is that your id is mapped as a Long in the hbm file but you use a String in the DlvryFac.java code. You'll need to change one or the other so they match.


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.