JAVA测试类调用DAO层查询数据库空指针异常
此为DAOImpl类publicTbAssignmentloadByLoginName(StringloginName){System.out.println(login...
此为DAOImpl类
public TbAssignment loadByLoginName(String loginName) {
System.out.println(loginName);
String hqlString = " from TbAssignment u where u.tbUser.userLoginname='"+loginName+"' ";
List<TbAssignment> list = this.getHibernateTemplate().find(hqlString);
if (list != null && list.size() > 0) {
return (TbAssignment) list.get(0);
} else {
return null;
}
}
测试类
@Test
public void t_pwd (){
TbAssignmentDaoImpl tbd = new TbAssignmentDaoImpl();
TbAssignment tb =tbd.loadByLoginName("XXXX");
System.out.println(tb.getTbUser().getUserLoginpwd());
} 展开
public TbAssignment loadByLoginName(String loginName) {
System.out.println(loginName);
String hqlString = " from TbAssignment u where u.tbUser.userLoginname='"+loginName+"' ";
List<TbAssignment> list = this.getHibernateTemplate().find(hqlString);
if (list != null && list.size() > 0) {
return (TbAssignment) list.get(0);
} else {
return null;
}
}
测试类
@Test
public void t_pwd (){
TbAssignmentDaoImpl tbd = new TbAssignmentDaoImpl();
TbAssignment tb =tbd.loadByLoginName("XXXX");
System.out.println(tb.getTbUser().getUserLoginpwd());
} 展开
展开全部
tb.getTbUser().getUserLoginpwd()肯定是这句报了异常
然后你看
List<TbAssignment> list = this.getHibernateTemplate().find(hqlString);
if (list != null && list.size() > 0) {
return (TbAssignment) list.get(0);
} else {
return null;
}
说明方法返回了null
你看看你的hqlString里面的名字数据库能查到么。
然后你看
List<TbAssignment> list = this.getHibernateTemplate().find(hqlString);
if (list != null && list.size() > 0) {
return (TbAssignment) list.get(0);
} else {
return null;
}
说明方法返回了null
你看看你的hqlString里面的名字数据库能查到么。
追问
select tu.user_loginpwd from TB_ASSIGNMENT ta , TB_USER tu where tu.user_id =ta.user_id and tu.user_loginname = 'XXXX'
在数据库查询是有结果的
可能是sessionfactory 没有加载上,启动tomcat 写Action 能查到,是不是不启动,不加载
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询