Spring and Hibernate adjust traps when auto-scan

Source: Internet
Author: User

Spring and hibernate integrate automatic scanning traps
The spring 2.5.6 automatic package scanning (Packagestoscan) feature is used when configuring Hibernate+spring.

This feature automatically scans the entity classes in the package to avoid the hassle of writing annotatedclasses. But when I use this feature, I've been encountering errors like this:

caused By:org.hibernate.MappingException:Unknown entity:com.mycompany.app.model.Users

The configuration in spring is:

Java code    <bean id= "Sessionfactory"  class= " Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean ">        <property name= "DataSource" >           < Ref bean= "DataSource"  />       </property>        <property name= "Hibernateproperties" >            <props>                <prop key= "Hibernate.dialect" >                    ${hibernate.dialect}                </prop>                <prop key= "HibernaTe.show_sql ">                    ${hibernate.show_sql}                </prop>                <prop key= "Hibernate.jdbc.fetch_size" >                    ${hibernate.jdbc.fetch_size}                </prop>                <prop key= "Hibernate.jdbc.batch_size" >                   ${ hibernate.jdbc.batch_size}                </prop>                <prop key= "Hibernate.c3p0.timeout" >                    ${hibernate.c3p0.timeout}                </prop>           </props>       </property>       <span style= " background-color:  #ff0000; " ><property name= "Packagestoscan"  value= "com.mycompany.app.model.*"  /></span>    </bean>  

But my entity class is clearly under Com.mycompany.app.model, why can't I scan it?

After a closer look at the document discovery, Packagestoscan's value should be configured as com.mycompany.app.*, which is the upper layer of the entity's package. This is really an incredible trap.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.