9
votes

3 Réponses :


25
votes

Si vous utilisez des classes JPA-Annoté, vous pouvez utiliser AnnotationSessFactoryBean Code> au lieu de LOCALALSESSFACORYBEAN CODE> et injecter les classes directement dans le haricot de ressort:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
       <list>
           <value>com.company.app.common.model.Account</value>
           <value>com.company.app.common.model.AccountCategory</value>
           <value>com.company.app.common.model.AssetType</value>
           <value>com.company.app.common.model.Book</value>
           <value>com.company.app.model.AssetTypeCategory</value>      
       </list>
    </property>
    <property name="mappingResources">
       <list>
          <value>Queries.hbm.xml</value>
       </list>
    </property>        
    <property name="hibernateProperties">
        <props>
            <prop key="dialect">org.hibernate.dialect.Oracle10gDialect</prop>
        </props>
    </property>
</bean>


2 commentaires

Où dois-je placer requêtes.hbm.xml qui contient des requêtes HQL?


@Derek: AnnotationSessionFactoryBean étend localsesssfactorybean , vous pouvez donc toujours utiliser toutes les mêmes propriétés qu'auparavant, y compris MappingResources .



9
votes

Une légère variation sur Skaffman's Réponse , j'ai utilisé la propriété Packagestoscan code> de la classe AnnotationSessFactoryBean Pour éviter toute la liste des noms de classe de modèle individuels:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan">
       <list>
           <value>com.company.app.common.model</value>
       </list>
    </property>
    <property name="mappingResources">
       <list>
          <value>Queries.hbm.xml</value>
       </list>
    </property>        
    <property name="hibernateProperties">
        <props>
            <prop key="dialect">org.hibernate.dialect.Oracle10gDialect</prop>
        </props>
    </property>
</bean>


0 commentaires

0
votes

Je faisais également face au même problème, et cela a fonctionné pour moi -

<bean id="auditCoreSessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
        <ref bean="auditCoreDataSource" />
    </property>
    <property name="packagesToScan" value="com.odeon.audit.dao.entity" />
    <property name="annotatedClasses">
        <list>
            <value>com.odeon.audit.dao.entity.AuditLogEntity</value>
            <value>com.odeon.audit.dao.entity.AuditLogApplicationEtity</value>
            <value>com.odeon.audit.dao.entity.AuditLogModuleEntity</value>
            <value>com.odeon.audit.dao.entity.AuditLogOperationEntity</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">#{auditCoreProp.getString('jdbc.dialect')}</prop>
            <prop key="hibernate.show_sql">#{auditCoreProp.getString('jdbc.show_sql')}</prop>
            <prop key="hbm2ddl.auto">#{auditCoreProp.getString('jdbc.hbm2ddl.auto')}
            </prop>
            <!-- prop key="hibernate.hbm2ddl.auto">create</prop -->
        </props>
    </property>
</bean>


0 commentaires