这是第一篇博客,不懂格式,随便写好了;
写代码的过程中自己常遇到的异常总结:
【框架】
【SpringMVC】
1.
type Exception report message Request processing failed; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Userinfo is not mapped [from Userinfo where eu_email='zhangsan@.com'] description The server encountered an internal error that prevented it from fulfilling this request. exception |
【原因1】:Dao实现类中hql语句的实体类名写错了;
<pre name="code" class="java"> @Override public Userinfo checkEmail(Userinfo user) { String hql="from userinfo where eu_email='"+user.getEu_email()+"'";//此处from后面跟正确的实体类名 Query query=sessionFactory.getCurrentSession().createQuery(hql); return (Userinfo) query.uniqueResult(); }
【原因2】:实体类中没有添加注解;
<pre name="code" class="java">package org.lanqiao.entity; import java.util.Date; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; @Entity @Table(name = "easybuy_user") public class Userinfo { public Userinfo() {}; @Id//我是主键注解 @GeneratedValue(generator = "system-uuid")//<span style="font-family: Arial, Helvetica, sans-serif;">我是主键注解,括号内的值可自定义,与下面的一致即可</span> @GenericGenerator(name = "system-uuid", strategy = "identity")//<span style="font-family: Arial, Helvetica, sans-serif;">我是主键注解</span> private String eu_user_id; public String getEu_user_id() { return eu_user_id; } public void setEu_user_id(String eu_user_id) { this.eu_user_id = eu_user_id; }
【补充:】如果实体类有主键的话,要在相应的属性前加注解,如上。