当前位置: 代码迷 >> Java Web开发 >> hibernate有关问题 帮帮忙
  详细解决方案

hibernate有关问题 帮帮忙

热度:531   发布时间:2016-04-17 13:55:07.0
hibernate问题 帮帮忙
IUserDao   为接口
import   com.software.vo.User;
public   interface   IUserDao   {

public   User   userVerify(String   username   ,   String   password);
}
UserDAO是实现了IUserDao的子类,用户验证用户是否合法
中一个验证方法:public   User   userVerify(String   userName,   String   userPwd)   {
//   TODO   自动生成方法存根
log.info( "验证用户名和密码的方法被执行!!!! ");
User   user=new   User();
final   String   HQL= "FROM   User   u   where   u.username=?   and   u.userpwd=? ";
String[]   parameterHql=new   String[2];
parameterHql[0]=userName;
parameterHql[1]=userPwd;
List   list=this.getHibernateTemplate().find(HQL,parameterHql);
if(list.size()!=0){
user=(User)list.get(0);
}
return   user;
}
测试类:
public   class   DaoTest   extends   AbstractDependencyInjectionSpringContextTests   {


private   IUserDao   userDao;
public   void   setUserDao(UserDAO   userDao)   {
this.userDao   =   userDao;
}
protected   String[]   getConfigLocations()   {
//   TODO   自动生成方法存根
return   new   String[]{ "classpath:com/software/dao/impl/applicationContext.xml "};
}
public   void   testVerify()
{
User   user   =   userDao.userVerify( "tang ",   "429 ");
assertNotNull(user);
}
/*public   void   test()
{
this.assertEquals( "true ",   "true ");
}*/如果去掉testVerify执行test()测试成功   说明classpath:com/software/dao/impl/applicationContext.xml "没有问题
}
报错:
验证用户名和密码的方法被执行!!!!
Loading   XML   bean   definitions   from   class   path   resource   [org/springframework/jdbc/support/sql-error-codes.xml]
SQLErrorCodes   loaded:   [DB2,   HSQL,   MS-SQL,   MySQL,   Oracle,   Informix,   PostgreSQL,   Sybase]
***   ERROR:     User   is   not   mapped.
***   ERROR:     Invalid   path:   'u.username '
***   ERROR:   <AST> :   unexpected   end   of   subtree
***   ERROR:     Invalid   path:   'u.userpwd '
***   ERROR:   <AST> :   unexpected   end   of   subtree

applicationContext.xml文件内容:
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   beans   PUBLIC   "-//SPRING//DTD   BEAN//EN "   "http://www.springframework.org/dtd/spring-beans.dtd ">

<beans>


<bean   id= "datasource "
class= "org.apache.commons.dbcp.BasicDataSource ">
<property   name= "driverClassName ">
<value> com.mysql.jdbc.Driver </value>
</property>
<property   name= "url ">
<value> jdbc:mysql://localhost:3306/computer </value>
</property>
<property   name= "username ">
<value> root </value>
</property>
<property   name= "password ">
<value> root </value>
</property>
</bean>
<bean   id= "sessionFactory "
class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property   name= "dataSource ">
  相关解决方案