ssh2整合出现的问题nested exception is org.hibernate.hql.ast.QuerySyntaxException

dxy860812 2014-02-05 10:58:40
action直接调的DAO。
dao代码为:
public class UserDao extends HibernateDaoSupport {
//普通用户登录验证
@SuppressWarnings("unchecked")
public boolean checkUser(String userName,String userPassword){
boolean flag = false;
String hql = "from Userinfo as user where user.username = '"+userName+"' and user.userpassword = '"+userPassword+"'";
List<Userinfo> userList = this.getHibernateTemplate().find(hql);
if(userList.size()>0){
flag = true;
}
return flag;
}

applicationContext.xml中这样注入
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


<!--指明hibernate配置文件的位置 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!--定义DAO -->
<bean id="userDao" class="com.dao.UserDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置LoginAction.java类文件 -->
<bean id="LoginAction" class="com.action.LoginAction" scope="prototype">
<property name="userDao">
<ref bean="userDao"/>
</property>
</bean>
</beans>

Userinfo.hbm.xml文件是自动生成的
<hibernate-mapping>
<class name="com.bean.Userinfo" table="userinfo" catalog="test">
<id name="userName" type="java.lang.String">
<column name="userName" length="6" />
<generator class="identity" />
</id>
<property name="userPassword" type="java.lang.String">
<column name="userPassword" length="45" not-null="true" />
</property>
<property name="userRole" type="java.lang.Integer">
<column name="userRole" not-null="true" />
</property>
</class>
</hibernate-mapping>

hibernate.cfg.xml文件:
里面有两句话我不是很理解
<property name="myeclipse.connection.profile">mysql</property>这句是什么意思?
<mapping resource="com/bean/Userinfo.hbm.xml" />这句我知道是配置该bean的xml

<hibernate-configuration>

<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">mysql</property>
<mapping resource="com/bean/Userinfo.hbm.xml" />



</session-factory>
...全文
170 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
BUG胡汉三 2014-02-07
  • 打赏
  • 举报
回复
你先运行:from Userinfo as user 如果可以的话,那么就是你后面的user.usernameuser.userpassword写错了!看看Userinfo类中属性是不是这个,hql必须换成实体类中的属性名称,而不是表的字段名称。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧