报了org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User] package com.model; import javax.persistence.Column; @Entity public int getId() { public void setId(int id) { public String getName() { public void setName(String name) { public String getPwd() { public void setPwd(String pwd) { |
|
20分 |
得要让Hibernate的SessionFactory扫到注解的实体啊
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="认真看这里" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.use_sql_comments">false</prop> <prop key="hibernate.max_fetch_depth">2</prop> <prop key="hibernate.jdbc.batch_size">100</prop> <prop key="hibernate.query.substitutions">true 1, false 0</prop> <prop key="hibernate.connection.SetBigStringTryClob">true</prop> <prop key="javax.persistence.validation.mode">none</prop> </props> </property> </bean> 另外,你没有配@Id啊,其余的两个字符串也得配上长度吧。 |
楼上说的对, packagesToScan 要包含你的实体类包
|
|
没配置好实体映射文件哦
|
|
20分 |
出现这中错误可能有以下两种原因:
1:配置文件没有被加载到hibernate的实体列表里面。 2:映射文件的字段与数据库字段不一致,或者名称不一致导致。 |
1楼说的对,配置文件需要映射到实体类
|