It's new to
hibernate3.6.7,using SSH framework,database is mysql 5,
I've got weird problem here.
attach DAO code:
UserMapDao.java(part):
Code:
@Override
public List queryUsers(Integer id,String name, String pass,String discrebtion) {
String hql="from com.User u where u.name=? and u.pass=?";
String[] a=new String[]{name,pass};
System.out.println("usermapdao List queryUsers a :"+a[0]+","+a[1]);
List tmp1= this.getHibernateTemplate().find(hql,a);
System.out.println("usermapdao List queryUsers size:"+tmp1.size());
return tmp1;
}
attached the website login.jsp, & got an error:
login.jsp:
Code:
<form name="login" action="login.action" method="post">
<input type="text" name="name" id="name" />
<input type="text" name="pass" id="pass" />
<input type="submit" value="submit">
</form>
com.User class:
package com;
Code:
public class User {
private Integer id;
private String name;
private String pass;
private String discrebtion;
public User(Integer id, String name, String pass, String discrebtion) {
super();
this.id = id;
this.name = name;
this.pass = pass;
this.discrebtion = discrebtion;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public User() {
// TODO Auto-generated constructor stub
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDiscrebtion() {
return discrebtion;
}
public void setDiscrebtion(String discrebtion) {
this.discrebtion = discrebtion;
}
}
user.hbm.xml as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2012-10-12 10:28:41 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.User" table="user">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="pass" type="java.lang.String">
<column name="PASS" />
</property>
<property name="discrebtion" type="java.lang.String">
<column name="DISCREBTION" />
</property>
</class>
</hibernate-mapping>
error as follows:
Hibernate:
select
user0_.ID as ID0_,
user0_.NAME as NAME0_,
user0_.PASS as PASS0_,
user0_.DISCREBTION as DISCREBT4_0_
from
user user0_
where
user0_.NAME=?
and user0_.PASS=?
java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.charAt(String.java:686)
at com.mysql.jdbc.StringUtils.escapeEasternUnicodeByt eStream(StringUtils.java:231)
at com.mysql.jdbc.StringUtils.getBytesWrapped(StringU tils.java:575)
at com.mysql.jdbc.PreparedStatement.setString(Prepare dStatement.java:4466)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.logicalcobwebs.proxool.ProxyStatement.invoke(P roxyStatement.java:100)
at org.logicalcobwebs.proxool.ProxyStatement.intercep t(ProxyStatement.java:57)
at $java.sql.Wrapper$$EnhancerByProxool$$14ff466.setS tring()
at org.hibernate.type.descriptor.sql.VarcharTypeDescr iptor$1.doBind(VarcharTypeDescriptor.java:52)
at org.hibernate.type.descriptor.sql.BasicBinder.bind (BasicBinder.java:91)
at org.hibernate.type.AbstractStandardBasicType.nullS afeSet(AbstractStandardBasicType.java:283)
at org.hibernate.type.AbstractStandardBasicType.nullS afeSet(AbstractStandardBasicType.java:278)
at org.hibernate.param.PositionalParameterSpecificati on.bind(PositionalParameterSpecification.java:68)
at org.hibernate.loader.hql.QueryLoader.bindParameter Values(QueryLoader.java:571)
at org.hibernate.loader.Loader.prepareQueryStatement( Loader.java:1716)
at org.hibernate.loader.Loader.doQuery(Loader.java:80 1)
at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:253 3)
at org.hibernate.loader.Loader.listIgnoreQueryCache(L oader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoa der.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(Que ryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performLis t(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:1 02)
at org.springframework.orm.hibernate3.HibernateTempla te$30.doInHibernate(HibernateTemplate.java:921)
at org.springframework.orm.hibernate3.HibernateTempla te$30.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTempla te.executeWithNativeSession(HibernateTemplate.java :374)
at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:912)
at dao.UserMapDao.queryUsers(UserMapDao.java:60)
at service.UserService.login(UserService.java:44)
at action.LoginAction.execute(LoginAction.java:17)
The weird point is while I'm using the hql like "FROM com.User",without any parameter for "where",it worked well.
I have doubted that if the proxool's version did not match hibernate, so I have tried to remove the proxool and used the mysql jdbc driver only,but it return the same exception.
It's weird.