映射是有的
实体类的注解:
使用session.createCriteria(User.class);是没有任何问题的
使用session.createQuery("from User")就报错User is not mapped
求教!!
http://blog.sina.com.cn/s/blog_4553489c01010ja7.html
session.createQuery("from User")这个是不是错了
这个实体类所在的包有没有扫描到呢,得要让Hibernate的SessionFactory扫到注解的实体啊 ,即检查hibernate的数据库连接配置信息中:
<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>
这个属性packagesToScan的值是否包含了User类所在的包名称。
@Entity
**@Table(name="tb_user") **