Why is “annotatedClasses” needed if there is @Entity?

后端 未结 1 1230
执笔经年
执笔经年 2021-02-07 09:19

Hello I\'m building spring-hibernate application. Do i realy need configuration from below ?

    
        
         


        
相关标签:
1条回答
  • 2021-02-07 10:15

    Use the docs, Luke!

    [...]Example for an AnnotationSessionFactoryBean bean definition:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="annotatedClasses">
            <list>
                <value>test.package.Foo</value>
                <value>test.package.Bar</value>
            </list>
        </property>
    </bean>
    

    Or when using classpath scanning for autodetection of entity classes:

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

    As you can see you have a choice between defining all classes explicitly or only the package for scanning. <context:component-scan/> does not recognize Hibernate/JPA annotations and hence has no effect.

    0 讨论(0)
提交回复
热议问题