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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With