Hibernate: user is not mapped
来源:互联网 发布:java中xml文件的作用 编辑:程序博客网 时间:2024/05/21 18:42
报错截取:
org.hibernate.hql.internal.ast.QuerySyntaxException: user is not mapped [from user where name=:name and password=:password] org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:96) org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120) org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234) org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126) org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
代码、配置段:
(1).applicationContext.xml
<!-- mappingResources用来列出全部映射文件 --><property name="annotatedClasses"><list><!-- 以下用来列出所有的PO类 --><value>edu.qtech.myclouds.domain.User</value></list></property><!-- 自动扫描注解方式配置的hibernate类文件 --><!-- <property name="packagesToScan"> --><!-- <list> --><!-- <value>edu.qtech.myclouds.domain.</value> --><!-- </list> --><!-- </property> -->
(2).User.java@Entity@Table(name="user")public class User {private int id;private String name;private String email;private String password;@Id@GeneratedValue(strategy = GenerationType.IDENTITY)public int getId() {return id;} ...}(3).UserDaoImpl
public User queryUser(String name,String password) {// TODO Auto-generated method stubString hql="from user where name=:name and password=:password";Query query=sessionFactory.getCurrentSession().createQuery(hql);query.setParameter("name", name);query.setParameter("password", password);List<User> list = query.list();if(list.size()>0){return list.get(0);}else{return null;}}
原因:
hql语句写错了。user应该写成User。因为hql操作的是类、实例、属性,而不再是 sql 语句的表名。
0 0
- Hibernate: user is not mapped
- SSH框架中hibernate 出现 user is not mapped 问题
- Hibernate报错(user is not mapped)
- hibernate:运行时出现user is not mapped问题
- SSHE框架中hibernate出现user is not mapped问题
- Hibernate Is Not Mapped
- (Hibernate) is not mapped
- Hibernate - is not mapped
- Hibernate异常: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User].
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User] 异常总结
- 异常积累:org.hibernate.hql.ast.QuerySyntaxError: User is not mapped. [from User where username=?]
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User] 异常总结
- Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User
- Hibernate Hql 查询出现 USER is not mapped [FROM USER WHERE
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
- Hibernate Hql 查询出现 USER is not mapped [FROM USER WHERE
- Hibernate Class Is Not Mapped
- JAVA变量(待完善)
- 微信开发
- C++菜鳥的成長之路(3)——Linux下的socket編程(2)
- LeetCode (Spiral Matrix II)
- openstack heat部署
- Hibernate: user is not mapped
- PHP表单处理与文件保存
- Unity3D中[SerializeField]特性的使用
- js与form交互方式总结
- [LeetCode
- 复杂度为nlgn的求幂算法
- 指针
- 惠普暗影2 pro ubuntu16.04安装nvidia显卡驱动
- Android 自定义自由选择时间区间的日历控件