Spring and hibernate.cfg.xml

Posted by Steve Kuo on Stack Overflow See other posts from Stack Overflow or by Steve Kuo
Published on 2009-01-23T03:27:30Z Indexed on 2010/05/23 16:41 UTC
Read the original article Hit count: 377

Filed under:
|
|
|

How do I get Spring to load Hibernate's properties from hibernate.cfg.xml?

We're using Spring and JPA (with Hibernate as the implementation). Spring's applicationContext.xml specifies the JPA dialect and Hibernate properties:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
        </props>
    </property>
</bean>

In this configuration, Spring is reading all the Hibernate properties via applicationContext.xml . When I create a hibernate.cfg.xml (located at the root of my classpath, the same level as META-INF), Hibernate doesn't read it at all (it's completely ignored).

What I'm trying to do is configure Hibernate second level cache by inserting the cache properties in hibernate.cfg.xml:

<cache 
    usage="transactional|read-write|nonstrict-read-write|read-only"
    region="RegionName"
    include="all|non-lazy"
/>

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate