Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate + Spring MVC: objects mapping configuration

is there any way to define objects in hibernate.cfg.xml by scope and not one by one?

For example, in Spring you can define all controllers by such annotation:

<context:component-scan base-package="crm.controller" />

Can I define hibernate classes in the same way? Or it must be defined one by one?

Thank you

like image 250
nKognito Avatar asked Feb 13 '12 13:02

nKognito


1 Answers

If you are using Spring MVC, you can configure it when setting up your sessionFactory. If you are using hbm files:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
        <list>
            <value>file1.hbm.xml</value>
            <value>file2.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties" ref="hibernateProperties"/>
</bean>

If you are using annotated classes:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.me.domain">
    <property name="hibernateProperties" ref="hibernateProperties"/>
</bean>
like image 136
stephen.hanson Avatar answered Sep 27 '22 23:09

stephen.hanson