-->
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.  [ 12 posts ] 
Author Message
 Post subject: help!error with Login demo
PostPosted: Wed May 17, 2006 10:12 am 
Newbie

Joined: Wed May 17, 2006 9:57 am
Posts: 9
hi,everyone

Hibernate version:
hibernate 3.1+struts1.27+myeclipse
Mapping documents:
Administrator.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Tue May 16 03:20:14 GMT 2006 -->

<hibernate-mapping>
<class name="com.kevin.form.Administrator" table="Administrator">
<id name="adminid" column="AdminID" type="java.lang.Long">
<generator class="native"/>
</id>
<property name="adminname" column="AdminName" type="java.lang.String" not-null="true" />
<property name="adminpassword" column="AdminPassword" type="java.lang.String" not-null="true" />
<property name="admindictionaryid" column="AdminDictionaryID" type="java.lang.String" not-null="true" />
<property name="adminquestion" column="AdminQuestion" type="java.lang.String" not-null="true" />
<property name="adminanswer" column="AdminAnswer" type="java.lang.String" not-null="true" />
</class>
</hibernate-mapping>

hibernate.cfg.xml
<?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">

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>

<session-factory>
<!-- properties -->
<property name="connection.username">gyf</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;database=ICShop</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.password">85356156</property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

<!-- mapping files -->
<mapping resource="com/kevin/form/Administrator.hbm.xml"/>
</session-factory>
</hibernate-configuration>

po -> Administrator.java

/*
* Created Tue May 16 03:20:15 GMT 2006 by MyEclipse Hibernate Tool.
*/
package com.kevin.form;

import java.io.Serializable;

/**
* A class that represents a row in the 'Administrator' table.
* This class may be customized as it is never re-generated
* after being created.
*/
public class Administrator implements Serializable
{
/** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */
private int hashValue = 0;
private Long adminid;
private String adminname;
private String adminpassword;
private String admindictionaryid;
private String adminquestion;
private String adminanswer;

/**
* Simple constructor of Administrator instances.
*/
public Administrator()
{
}


public Administrator(String adminname,String adminpassword) {
this.adminname=adminname;
this.adminpassword=adminpassword;
}

/**
* Return the simple primary key value that identifies this object.
* @return java.lang.Long
*/
public Long getAdminid()
{
return adminid;
}

/**
* Set the simple primary key value that identifies this object.
* @param adminid
*/
public void setAdminid(Long adminid)
{
this.hashValue = 0;
this.adminid = adminid;
}

/**
* Return the value of the AdminName column.
* @return java.lang.String
*/
public String getAdminname()
{
return this.adminname;
}

/**
* Set the value of the AdminName column.
* @param adminname
*/
public void setAdminname(String adminname)
{
this.adminname = adminname;
}

/**
* Return the value of the AdminPassword column.
* @return java.lang.String
*/
public String getAdminpassword()
{
return this.adminpassword;
}

/**
* Set the value of the AdminPassword column.
* @param adminpassword
*/
public void setAdminpassword(String adminpassword)
{
this.adminpassword = adminpassword;
}

/**
* Return the value of the AdminDictionaryID column.
* @return java.lang.String
*/
public String getAdmindictionaryid()
{
return this.admindictionaryid;
}

/**
* Set the value of the AdminDictionaryID column.
* @param admindictionaryid
*/
public void setAdmindictionaryid(String admindictionaryid)
{
this.admindictionaryid = admindictionaryid;
}

/**
* Return the value of the AdminQuestion column.
* @return java.lang.String
*/
public String getAdminquestion()
{
return this.adminquestion;
}

/**
* Set the value of the AdminQuestion column.
* @param adminquestion
*/
public void setAdminquestion(String adminquestion)
{
this.adminquestion = adminquestion;
}

/**
* Return the value of the AdminAnswer column.
* @return java.lang.String
*/
public String getAdminanswer()
{
return this.adminanswer;
}

/**
* Set the value of the AdminAnswer column.
* @param adminanswer
*/
public void setAdminanswer(String adminanswer)
{
this.adminanswer = adminanswer;
}

/**
* Implementation of the equals comparison on the basis of equality of the primary key values.
* @param rhs
* @return boolean
*/
public boolean equals(Object rhs)
{
if (rhs == null)
return false;
if (! (rhs instanceof Administrator))
return false;
Administrator that = (Administrator) rhs;
if (this.getAdminid() != null && that.getAdminid() != null)
{
if (! this.getAdminid().equals(that.getAdminid()))
{
return false;
}
}
return true;
}

/**
* Implementation of the hashCode method conforming to the Bloch pattern with
* the exception of array properties (these are very unlikely primary key types).
* @return int
*/
public int hashCode()
{
if (this.hashValue == 0)
{
int result = 17;
int adminidValue = this.getAdminid() == null ? 0 : this.getAdminid().hashCode();
result = result * 37 + adminidValue;
this.hashValue = result;
}
return this.hashValue;
}

}

formbean->AdminLoginForm.java

//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.kevin.form;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;

/**
* MyEclipse Struts
* Creation date: 05-16-2006
*
* XDoclet definition:
* @struts:form name="adminLoginForm"
*/
public class AdminLoginForm extends ValidatorForm {

// --------------------------------------------------------- Instance Variables

/** adminPassword property */
private String adminPassword;

/** adminName property */
private String adminName;

// --------------------------------------------------------- Methods

/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validator(
ActionMapping mapping,
HttpServletRequest request) {

throw new UnsupportedOperationException(
"Generated method 'validate(...)' not implemented.");
}

/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {

this.adminName=null;
this.adminPassword=null;
}



/**
* Returns the adminPassword.
* @return String
*/
public String getAdminPassword() {
return adminPassword;
}

/**
* Set the adminPassword.
* @param adminPassword The adminPassword to set
*/
public void setAdminPassword(String adminPassword) {
this.adminPassword = adminPassword;
}

/**
* Returns the adminName.
* @return String
*/
public String getAdminName() {
return adminName;
}

/**
* Set the adminName.
* @param adminName The adminName to set
*/
public void setAdminName(String adminName) {
this.adminName = adminName;
}

}

action -> AdminLoginAction.java
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.kevin.action;


import java.util.*;

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 org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.kevin.form.*;
import com.kevin.struts.HibernateUtil;
/**
* MyEclipse Struts
* Creation date: 05-16-2006
*
* XDoclet definition:
* @struts:action path="/adminLoginAction" name="adminLoginForm" input="/Login.jsp" scope="request" validate="true"
*/
public class AdminLoginAction extends Action {

// --------------------------------------------------------- Instance Variables

// --------------------------------------------------------- Methods
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)throws HibernateException{

String adminName=request.getParameter("adminName");
String adminPassword=request.getParameter("adminPassword");

System.out.println(adminName);
System.out.println(adminPassword);

//AdminLoginForm loginForm=new AdminLoginForm();
Administrator admin=new Administrator();


Session session=HibernateUtil.getSession();

Transaction tx=session.beginTransaction();
try{


Query query=session.createQuery("from Administrator admin where admin.adminname='"+adminName+"'and admin.adminpassword='"+adminPassword+"'");
System.out.println("query is :"+adminName);
//System.out.println("loginForm:"+loginForm.getAdminName());
//System.out.println("Admin.getAdmin:"+admin.getAdminname());
query.setString("adminname",adminName);
query.setString("adminpassword",adminPassword);
List list=query.list();
System.out.println("query.list().getadmin"+query.list().get(1));
for (ListIterator iterator=list.listIterator(); iterator.hasNext(); )
{
admin = (Administrator) iterator.next();
};

}catch (Exception e) {
System.out.println(e.getMessage());
}


tx.commit();

HibernateUtil.closeSession();
if(!(admin.getAdminname().equals("")))
return(mapping.findForward("success"));
else
return(mapping.findForward("error"));
}

}

Debug level Hibernate log excerpt:
log4j messages:
Parameter adminname does not exist as a named parameter in [from Administrator admin where admin.adminname='admin'and admin.adminpassword='admin']


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 10:58 am 
Newbie

Joined: Wed Apr 26, 2006 8:28 am
Posts: 8
Location: Germany
Code:
Query query=session.createQuery("from Administrator admin where admin.adminname='"+adminName+"'and admin.adminpassword='"+adminPassword+"'");
query.setString("adminname",adminName);
query.setString("adminpassword",adminPassword);


This can't work, since you set named parameters with setString but you have no named parameters in you query.

Your query should be like this:
Code:
Query query=session.createQuery("from Administrator admin where admin.adminname=:adminName and admin.adminpassword=:adminPassword");
query.setString("adminname",adminName);
query.setString("adminpassword",adminPassword);


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 11:01 am 
Newbie

Joined: Wed Apr 26, 2006 8:28 am
Posts: 8
Location: Germany
sorry, case was wrong, should be

Code:
Query query=session.createQuery("from Administrator admin where admin.adminname=:adminname and admin.adminpassword=:adminpassword");
query.setString("adminname", adminName);
query.setString("adminpassword", adminPassword);


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 8:25 pm 
Newbie

Joined: Wed May 17, 2006 9:57 am
Posts: 9
tlueckow wrote:
sorry, case was wrong, should be

Code:
Query query=session.createQuery("from Administrator admin where admin.adminname=:adminname and admin.adminpassword=:adminpassword");
query.setString("adminname", adminName);
query.setString("adminpassword", adminPassword);


thank you for you reply!

but I've do it according to your step!
now log4j is:
could not execute query

tomcat logs is:
2006-05-18 00:12:03 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at com.kevin.action.AdminLoginAction.execute(AdminLoginAction.java:87)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)


I am very confused for this!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 3:58 am 
Newbie

Joined: Wed Apr 26, 2006 8:28 am
Posts: 8
Location: Germany
Have a look at line 87:

Code:
if(!(admin.getAdminname().equals("")))


I think you get no result and getAdminname() returns null because you work with the empty Administrator object from line 57.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 9:35 am 
Newbie

Joined: Wed May 17, 2006 9:57 am
Posts: 9
tlueckow wrote:
Have a look at line 87:

Code:
if(!(admin.getAdminname().equals("")))


I think you get no result and getAdminname() returns null because you work with the empty Administrator object from line 57.


I've check my code again,
now I update my code at line 87:
if(admin!=null && admin.getAdminname().equals("")!=true)
return(mapping.findForward("success"));

but it still logs :

could not execute query

I found :
Query query=session.createQuery("from Administrator a where a.adminname=:adminname and a.adminpassword=:adminpassword");
could not exeute !

why?

thank you !


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 3:12 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
Try setting the property
<property name="show_sql">true</property> in hibernate.cfg.xml

Log4j will show the generated sql. It will look something like this:

select admin0_.adminid as adminid24_, admin0_.adminname as adminname, admin0_.adminpassword as adminpassword, admin0_.admindictionaryid as admindictionaryid, admin0_.adminquestion as adminquestion, admin0_.adminanswer as adminanswer from Administrator admin0_ where admin0_.adminname=? and admin0_.adminpassword=?

Copy that sql and execute it on the database, do you get an error then?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 21, 2006 4:46 am 
Newbie

Joined: Wed May 17, 2006 9:57 am
Posts: 9
emilSverige wrote:
Try setting the property
<property name="show_sql">true</property> in hibernate.cfg.xml

Log4j will show the generated sql. It will look something like this:

select admin0_.adminid as adminid24_, admin0_.adminname as adminname, admin0_.adminpassword as adminpassword, admin0_.admindictionaryid as admindictionaryid, admin0_.adminquestion as adminquestion, admin0_.adminanswer as adminanswer from Administrator admin0_ where admin0_.adminname=? and admin0_.adminpassword=?

Copy that sql and execute it on the database, do you get an error then?


yes,get an error:
[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error

why?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 21, 2006 5:01 am 
Newbie

Joined: Wed May 17, 2006 9:57 am
Posts: 9
I add <property name="show_sql">true</property> in hibernate.cfg.xml
Log4j show the generated sql.
select administra0_.AdminID as AdminID0_, administra0_.AdminName as AdminName0_, administra0_.AdminPassword as AdminPas3_0_, administra0_.AdminDictionaryID as AdminDic4_0_, administra0_.AdminQuestion as AdminQue5_0_, administra0_.AdminAnswer as AdminAns6_0_ from Administrator administra0_ where administra0_.AdminName=? and administra0_.AdminPassword=?

I copy this sql and execute it on the database ,error:
[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error
if I delete where administra0_.AdminName=? and administra0_.AdminPassword=? ,it can execute on database


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 8:30 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
I would guess that there's something wrong with your database.

If you have no important data in any table you can let Hibernate drop the entire DB and then create it from scratch (To match your hibernate mapping):

Open hibernate.cfg.xml.
Under <session-factory>, add the following line:

<property name="hibernate.hbm2ddl.auto">create</property>


If you don't want to loose any data or unmapped tables/columns,
add this line instead:
<property name="hibernate.hbm2ddl.auto">update</property>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 8:31 am 
Newbie

Joined: Wed May 17, 2006 9:57 am
Posts: 9
thank you for all reply,help me,I 'm so confused


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 9:09 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
No problem, just ask ahead! And if someone eventually solves your problem, don't forget to rate him/her.


Have you tried to regenerate the DB as I suggested and are still confused, or are you confused about how to do it?

Since you get an error when you try to run the SQL query, i would guess that you perhaps have misspellt the name of some column.
If you use hibernate.hbm2ddl.auto, you don't have to write your own create scripts, hibernate will do it for you.


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