-->
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.  [ 6 posts ] 
Author Message
 Post subject: Getting org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Tue Aug 19, 2008 5:47 am 
Newbie

Joined: Tue Aug 19, 2008 5:08 am
Posts: 3
Location: India
I am trying to retrieve the values in the database.
I have added all the required files and libraries.
Its showing an error -table is not mapped
here is code

Version of hibernate: Hibernate3.3.0

Mapping documents: Message.hbm.xml
The mapping file code is given below

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="helloworld.Message"
table="SRInbox">


<id name="userId" type="java.lang.String"
column="UserId" length="10">
<generator class="increment" />
</id>

<property name="uGroup" type="java.lang.String" column="UGroup" length="10" />
<property name="sFrom" type="java.lang.String" column="SFrom" length="30" />
<property name="subject" type="java.lang.String" column="Subject" length="30" />
<property name="sendTime" type="java.lang.String" column="SendTime" length="20" />
<property name="priority" type="java.lang.String" column="Priority" length="20" />
<property name="screen" type="java.lang.String" column="Screen" />
<property name="srCategory" type="java.lang.String" column="SRCategory" length="40" />
<property name="srSubCategory" type="java.lang.String" column="SRSubCategory" />
<property name="size" type="java.lang.String" column="Size" length="10" />
<property name="screenFile" type="java.lang.String" column="ScreenFile"/>
<property name="status" type="java.lang.String" column="Status" length="10" />
<property name="serverProcessTime" type="java.lang.String" column="ServerProcessTime" length="25" />

</class>

</hibernate-mapping>


My configuration file is hibernate.cfg.xml
the code is
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="connection.url">
jdbc:sqlserver://202.0.0.202:1433;databaseName=Data;
</property>

<property name="connection.username">
DBAdmin
</property>
<property name="connection.password">
II@admin
</property>
<!-- Set AutoCommit to true -->
<property name="connection.autocommit">
true
</property>
<!-- SQL Dialect to use. Dialects are database specific -->
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Mapping files -->
<mapping resource="helloworld/Message.hbm.xml" />

</session-factory>
</hibernate-configuration>




Session session =
HibernateUtil.getSessionFactory().openSession();String SQL_QUERY ="Select UserId from SRInbox";


Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();)
{
Object[] row = (Object[]) it.next();
System.out.println(" UserId: " + row[0]);}

session.close();


Full stack trace of any exception that occurs:Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: SRInbox is not mapped [Select UserId from SRInbox]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
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:251)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
at helloworld.HelloWorld.main(HelloWorld.java:38)


I am using sql server 2005. i tried to connect to the database. I could do that.

The persistence class is message.java and
the code for is


public class Message
{
Message() {}
private String userId;
private String uGroup;
private String sFrom;
private String subject;
private String sendTime;
private String priority;
private String screen;
private String srCategory;
private String srSubCategory;
private String size;
private String screenFile;
private String status;
private String serverProcessTime;

public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId =userId;
}
public String getuGroup(){
return uGroup;
}
public void setuGroup(String uGroup) {
this.uGroup =uGroup;
}
public String getsFrom() {
return sFrom;
}
public void setsFrom(String sFrom) {
this.sFrom = sFrom;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getSendTime() {
return sendTime;
}
public void setSendTime(String sendTime) {
this.sendTime = sendTime;
}
public String getPriority() {
return priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
public String getScreen() {
return screen;
}
public void setScreen(String screen) {
this.screen = screen;
}
public String getSrCategory() {
return srCategory;
}
public void setSrCategory(String srCategory) {
this.srCategory = srCategory;
}
public String getSrSubCategory() {
return srSubCategory;
}
public void setSrSubCategory(String srSubCategory) {
this.srSubCategory = srSubCategory;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getscreenFile() {
return screenFile;
}
public void setScreenFile(String screenFile) {
this.screenFile = screenFile;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getServerProcessTime() {
return serverProcessTime;
}
public void setServerProcessTime(String serverProcessTime) {
this.serverProcessTime = serverProcessTime;
}

}





Table is already created ,but showing table is not mapped...

Please Help me


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 7:40 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You should use the name of your objects/object properties, not the names of the tables/column. Eg.

Code:
select m.userId from Message m


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 8:17 am 
Newbie

Joined: Tue Aug 19, 2008 5:08 am
Posts: 3
Location: India
Thank u......
Now its working


Top
 Profile  
 
 Post subject: Re: Getting org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Thu Oct 28, 2010 10:07 am 
Newbie

Joined: Fri Oct 15, 2010 10:30 am
Posts: 3
It helped me also. Thanks.


Top
 Profile  
 
 Post subject: Re: Getting org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Tue Nov 02, 2010 7:03 am 
Newbie

Joined: Wed Oct 27, 2010 8:31 am
Posts: 2
Thank you!


Top
 Profile  
 
 Post subject: Re:Getting org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Fri Jul 22, 2011 3:00 am 
Newbie

Joined: Fri Jul 22, 2011 2:36 am
Posts: 1
Thank you very much...


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