User is not mapped [from User]

shuizhonghua2 2010-08-23 01:32:28
错误语句: List<User> users = this.hibernateTemplate.find("from User");
相关报错:
Struts has detected an unhandled exception:

Messages:
User is not mapped [from User]
User is not mapped [from User]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
File: org/hibernate/hql/ast/util/SessionFactoryHelper.java
Line number: 181
Stacktraces

org.springframework.orm.hibernate3.HibernateQueryException: User is not mapped [from User]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)

User类:
@Entity(name="user")
public class User {
private int id;
private String username;
private String password;
private String phone;
private String addr;

//get 和 set 省略
}

hibernate自动的表

ApplicationContext.xml


<context:annotation-config />
<context:component-scan base-package="com.shopping" />



<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/shoppingssh" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />

<property name="annotatedClasses">
<list>
<value>com.shopping.model.User</value>
</list>
</property>

<property name="hibernateProperties">
<value>
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate.hbm2ddl.auto = create
</value>
</property>

</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>


求解答
...全文
907 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuizhonghua2 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 madfatso 的回复:]

@Entity
@Table(name = "user")
[/Quote]

正解 谢谢 散分
madFatso 2010-08-23
  • 打赏
  • 举报
回复
@Entity
@Table(name = "user")

81,094

社区成员

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

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