Mysql
 sql >> Base de données >  >> RDS >> Mysql

Comment configurer hibernate.cfg.xml en applicationContext.xml en tant que dataSource ?

Voici un exemple de comment utiliser hibernate.cfg.xml et comment configurer votre sessionFactory avec.

cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
    <property name="connection.datasource">java:comp/env/jdbc/oracle</property>
    <property name="dialect">
        org.hibernate.dialect.Oracle9iDialect
    </property>

    .. other config goes here.....
   </session-factory>
</hibernate-configuration>

Ajoutez ceci à votre applicationContext.xml.

<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
        <property name="mappingResources">
            <list>              
                <value>...your hbm file location...</value>
            </list>
        </property>
    </bean>