Yes, you can access both the files and use them to create the Session Factory. But instead of doing this inside your hibernate configuration file. I would suggest to do it inside the application context because first, your hibernate.cfg.xml does not contain the name space required to declare the bean and secondly. it needs to be read by the context configurer so, that it can instantiate the bean.
In you application context, you can create a data source using the hibernate.properties file like this..
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="{location of hibernate properties files}" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${db.driverClassName}"/>
<property name="jdbcUrl" value="${db.databaseurl}"/>
....other properties...
</bean>
Finally, create a session factory like this
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="configLocation">
<beans:value>classpath:hibernate.cfg.xml</beans:value>
</beans:property>
<beans:property name="configurationClass">
<beans:value>org.hibernate.cfg.AnnotationConfiguration</beans:value>
</beans:property>
This would create a session factory singleton instance for you which could be accessed using Autowiring.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…