-->
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: table is not mapped [ from Bean]
PostPosted: Mon Jan 12, 2009 8:24 am 
Newbie

Joined: Fri Jan 09, 2009 8:50 am
Posts: 5
Location: Bangalore
hai i have this things in my webapp

1) index.html
3) Action Class
4) DAO

in index.html i have one submit button if i click on that button the submit action will execute the DAO code which is has hibernate coding to retrive the list from the database table Usersys and my code is as follows

index.html
===================================================================================



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form name="listusers" action="listUsers.orca" method="post">
<input type="submit" value="Submit">
</form>


</body>
</html>
===================================================================================


Action Class
===================================================================================
package com.simple.stuff.Action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import java.util.ArrayList;

import com.simple.stuff.DAO.*;
public class RetriveUserAction extends Action
{

public ActionForward execute(ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException
{
ArrayList list = new ArrayList();
System.out.println("this is to retrive the user info on the usersys table");
UserDAO obj = new UserDAO();
list = obj.retriveUsers();
request.setAttribute("list", list);
if(list.size()>0)
{
request.setAttribute("list",list);
mapping.findForward("display");
}

else
mapping.findForward("nodata");
return null;

}

}


==================================================================================


DAO

===================================================================================

package com.simple.stuff.DAO;

import java.util.ArrayList;

import org.hibernate.Session;

import util.HibernateUtil;

import com.simple.stuff.Bean.UserNameBean;

public class UserDAO {


public String saveUserInfo(UserNameBean UserNameBean)
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(UserNameBean);
session.getTransaction().commit();

return "1";
}


public ArrayList retriveUsers()
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

ArrayList<UserNameBean> userList = new ArrayList<UserNameBean>(session.createQuery(" from Usersys").list());

for(UserNameBean user : userList)
{
System.out.println("This is the demo "+user.getUsername()+"This is the password "+user.getSubPassword());
}

session.getTransaction().commit();

HibernateUtil.getSessionFactory().close();

return userList;
}


}
====================================================================================


There is no Error in the hibernate configuration file as i have sucessfull compiled the user insertion example

when i have executed the following example i am getting

"Usersys is not mapped [ from Usersys]"

here is the error log

====================================================================================


Jan 12, 2009 5:11:09 PM org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class org.hibernate.hql.ast.QuerySyntaxException
Jan 12, 2009 5:11:09 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet simpleStuff threw exception
org.hibernate.hql.ast.QuerySyntaxException: Usersys is not mapped [ from Usersys]
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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
at $Proxy1.createQuery(Unknown Source)
at com.simple.stuff.DAO.UserDAO.retriveUsers(UserDAO.java:59)
at com.simple.stuff.Action.RetriveUserAction.execute(RetriveUserAction.java:25)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
======================================================================================


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 9:32 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
...session.createQuery(" from Usersys")....


In HQL you need to use the class names and not the table names. Since it seems like you are expecting the query to return UserNameBean objects it is more likely that the following should work:

Code:
...session.createQuery(" from UserNameBean")...


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.