-->
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.  [ 1 post ] 
Author Message
 Post subject: table is not mapped - hibernate hsql query in struts 2
PostPosted: Sun Feb 26, 2012 9:32 am 
Newbie

Joined: Sun Feb 26, 2012 8:02 am
Posts: 2
Code:
i want to check & enter login page when i put username and password depends on admin_user checkbox is checked 'true' from the database and submit button action. but here i getting table is not mapped.
follow error is here
[code]

org.hibernate.hql.ast.QuerySyntaxException: USER is not mapped [ from USER where USER_NAME=:loginName and USER_ADMINISTRATOR=1]
   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)
        .....
[/code]

i have following this things in my java project on eclipse indigo
[list]LoginPage.jsp[/list]
[list]NewEntryAction.java[/list]
[list]NewEntryDAOImpl.java[/list]
[list]NewEntryDAO.java[/list]
[list]struts.xml[/list]
[list]hibernate.cfg.xml[/list]

how do i correct it pls guide me....thanks 
[b]LoginPAge.jsp[/b]
[code]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!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>Login Page</title>
<script type="text/javascript">
function validate()
{
   var u_name=document.form1.loginName.value;
   var pass=document.form1.password.value;
   if((u_name=="" && pass==""))
      {
      alert("please! Enter your correct name and password");
      document.form1.loginName.focus();
     // alert("1");
      return false;
      }
   else if((u_name=="" && pass!="")||(u_name!="" && pass==""))
   { alert("proper name and password only accept");
     document.form1.loginName.focus();
      return false;
   }
   else { alert("Welcome !");
       document.form1.action="newLoginPageEnter";
       document.form1.submit();
       return true;
    }
}
</script>
<body bgcolor="#F5DEB3">
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror/>
</div>
</s:if>
<center><s:form  name="form1">
<font face="verdana,arial" size=-1 color="green"><strong>Login Name:</strong></font><input type="text" name="loginName">
<font face="verdana,arial" size=-1 color="green"><strong>Password:</strong></font><input type="password" name="password">
<input type="button" value="Login" onclick="validate();"/>
<input type="reset" value="Clear"/>Lost your login name or password? Find it&nbsp;<a href="<s:url action='registerPage'/>"><font size="3">Register</font></a>
</center>
</s:form>
</center>
</body>
</html>
[/code]

[b]NewEntryAction.java[/b]
[code]
package com.vaannila.web;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.vaannila.dao.NewEntryDAO;
import com.vaannila.dao.NewEntryDAOImpl;
import com.vaannila.domain.User;
public class NewEntryAction extends ActionSupport implements ModelDriven<User> {
   private static final long serialVersionUID = -6659925652584240539L;
        private User user=new User();
   private NewEntryDAO newUserDAO=new NewEntryDAOImpl();
   private String login_name;
        public String list()
   { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
      login_name=request.getParameter("loginName");
      User user = newUserDAO.listNew(login_name);
      if (user==null){
         addActionError("you are a invalide user. Pls Register! ");
         return INPUT;
      }
      else{
         addActionMessage("You are valid user!");
         return SUCCESS;
           }
   }
@Override
   public User getModel()
   { return user; }
   public User getUser() { return user; }
   public void setUser(User user) { this.user = user; }
}
[/code]

// [b]NewEntryDAOImpl.java[/b]
[code]
import com.opensymphony.xwork2.inject.Factory;
import com.vaannila.domain.NewEntry;
import com.vaannila.domain.User;

public class NewEntryDAOImpl implements NewEntryDAO{

   @SessionTarget
   Session session;
   
   @TransactionTarget
   Transaction transaction;

   public User listNew(String loginName)
   {
       User user=null;
      try {
         
      AnnotationConfiguration config = new AnnotationConfiguration();
      config.addAnnotatedClass(User.class);
      SessionFactory factory= config.configure().buildSessionFactory();
      Session session = factory.getCurrentSession(); 
      session.beginTransaction();//lets hope an id of 1 exists! 
      String queryString = " from USER where USER_NAME=:loginName and USER_ADMINISTRATOR=1";
      Query query=session.createQuery(queryString);
      query.setString("USER_NAME",loginName);
      Object queryResult=query.uniqueResult();
      if(queryResult==null)
      {
         System.out.println("true. the queryResult is null");
         //return true;
         
      }
      else
      {
         user=(User)queryResult;
         session.getTransaction().commit();
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
      return user;
   }
[/code]

[b]User.java[/b]
[code]
package com.vaannila.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="USER")
public class User implements Serializable {

   private Long id;
   private String name;
   private String password;
   private Boolean admin;
   
   @Id
   @GeneratedValue
   @Column(name = "ID")
   public Long getId() {
      return id;
   }
   public void setId(Long id) {
      this.id = id;
   }
   
   
   @Column(name = "USER_NAME")
   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }
   
   @Column(name="USER_PASSWORD")
   public String getPassword()
   {
      return password;
   }
   public void setPassword(String pass)
   {
      password=pass;
   }
   
   @Column(name="USER_ADMINISTRATOR")
   public Boolean getAdmin()
   {
      return admin;
   }
   public void setAdmin(Boolean admin)
   {
      this.admin=admin;
   }
}

[b]NewEntry.java[/b]
[/code]
package com.vaannila.dao;
import com.vaannila.domain.NewEntry;
import com.vaannila.domain.User;
public interface NewEntryDAO {

   public void saveOrUpdateNew(NewEntry newUSer);
   public User listNew(String loginName);
}

[b]struts.xml[/b]

[quote]
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.custom.i18n.resources" value="user"/>
   <package name="default" extends="hibernate-default">
<action name="newLoginPageEnter" method="list" class="com.vaannila.web.NewEntryAction">
      <result name="success" >/registrationsuccess.jsp</result>
      <result name="input">/loginPage.jsp</result>
      <result name="error">/loginPage.jsp</result>
      </action>
</package>
</struts>
[/quote]

[b]hibernate.cfg.xml[/b]

[code]
<?xml version="1.0" encoding="UTF-8"?>
<!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="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:jtds:sqlserver://localhost:1433/perumal</property>
      <property name="hibernate.connection.username">sa</property>
      <property name="connection.password">sql2008</property>
      <property name="connection.pool_size">1</property>
      <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
      <property name="show_sql">true</property>
      <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
          <property name="hbm2ddl.auto">update</property>
      <mapping class="com.vaannila.domain.User" />
   </session-factory>
</hibernate-configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.