-->
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: weird problem in hibernate
PostPosted: Sun Oct 14, 2012 11:48 pm 
Newbie

Joined: Sun Oct 14, 2012 11:29 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: weird problem in hibernate
PostPosted: Mon Oct 15, 2012 4:41 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
When I use hql, I usually would do something like this: "from ... where u.name=:name and u.pass=:pass" and specifically set the parameters.
What happens if you skip the parameters? And what happens if you just set one parameter?


Top
 Profile  
 
 Post subject: Re: weird problem in hibernate
PostPosted: Mon Oct 15, 2012 5:47 am 
Newbie

Joined: Tue Aug 07, 2012 4:58 am
Posts: 4
you can try to print the in-parameter of method queryUsers() and also a of type String[].


Top
 Profile  
 
 Post subject: Re: weird problem in hibernate
PostPosted: Mon Oct 15, 2012 9:14 pm 
Newbie

Joined: Sun Oct 14, 2012 11:29 pm
Posts: 4
Kenny_Zhang wrote:
you can try to print the in-parameter of method queryUsers() and also a of type String[].

I've tried,parameters & String[] is ok.


Top
 Profile  
 
 Post subject: Re: weird problem in hibernate
PostPosted: Mon Oct 15, 2012 9:16 pm 
Newbie

Joined: Sun Oct 14, 2012 11:29 pm
Posts: 4
Lino Cibran wrote:
When I use hql, I usually would do something like this: "from ... where u.name=:name and u.pass=:pass" and specifically set the parameters.
What happens if you skip the parameters? And what happens if you just set one parameter?


while I was using the hql like "FROM com.User" without any parameters,it worked well.
if I set single parameter,it return the same exception.


Top
 Profile  
 
 Post subject: Re: weird problem in hibernate
PostPosted: Mon Oct 15, 2012 9:56 pm 
Newbie

Joined: Sun Oct 14, 2012 11:29 pm
Posts: 4
Hey,guys.
I find the other point,while I change the code:
String[] a=new String[]{name,pass};
as:
String[] a=new String[]{"\'"+name+"\'","\'"+pass+"\'"};

the exception "java.lang.StringIndexOutOfBoundsException"
can be fixed , but there is no data found.

I attched the source of "com.mysql.jdbc.PreparedStatement.setString",found that,there is a match case,and this exception was thrown while matching.


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.