Hibernate配置Xml

Hibernate配置Xml,xml,hibernate,spring,configuration,Xml,Hibernate,Spring,Configuration,我正在使用hibernate作为ORM开发一个java web应用程序。可以将Hibernate.cfg.xml与application config.xml合并吗?这是可能的,因为在幕后,当您按照以下方式设置会话工厂时(让我们合并Hibernate.cfg.xml和applicationContext.xml属性) 《小心》API说: 配置设置可以从指定为“configLocation”的Hibernate XML文件读取,也可以完全通过此类读取。典型的本地配置包括一个或多个“映射资源”、各种

我正在使用hibernate作为ORM开发一个java web应用程序。可以将Hibernate.cfg.xml与application config.xml合并吗?

这是可能的,因为在幕后,当您按照以下方式设置会话工厂时(让我们合并Hibernate.cfg.xml和applicationContext.xml属性)

《小心》API说:

配置设置可以从指定为“configLocation”的Hibernate XML文件读取,也可以完全通过此类读取。典型的本地配置包括一个或多个“映射资源”、各种“hibernateProperties”(并非严格必需)和SessionFactory应该使用的“数据源”。后者也可以通过Hibernate属性指定,但“dataSource”支持任何Spring配置的数据源,而不是依赖Hibernate自己的连接提供程序


关于,您可以将spring与hibernate结合使用。 您只需要为hibernate配置创建一个bean,并使用aop或bean名称将其加载到应用程序启动中

以下是一个教程:
还有一个:

来自Spring的应用程序确认???
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    <property name="mappingResources">
        <list>
            <value>br/com/myApp/domain/User.hbm.xml</value>
            <value>br/com/myApp/domain/Group.hbm.xml</value>
        </list>
    </property>
</bean>
// configure load hibernate.cfg.xml from the classpath
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");

configuration.addResource("br/com/myApp/domain/User.hbm.xml");
configuration.addResource("br/com/myApp/domain/Group.hbm.xml");

SessionFactory sessionFactory = configuration.buildSessionFactory();