Hi,
I've used hibernate for a while, but am new to integrating it into spring beans. I have a context XML file (as below). The hibernate properties specified are the same as I use in my hibernate unit tests. When I run the hibernate unit tests standalone, the database is auto-created on startup. However, when I use spring to get the session factory, hibernate is not auto creating the db.
I know I'm probably doing something wrong, but I can't figure out what it is![]()
Thanks,
John.
Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "file://localhost/C:/development/spring-framework-2.1-m1/dist/resources/spring-beans-2.0.dtd"> <beans> <bean id="h2DataSource" class="com.foo.util.persistence.DataSource"> <property name="driverClassName"> <value>org.h2.Driver</value> </property> <property name="url"> <value>jdbc:h2:mem:InMemoryDatabase</value> </property> </bean> <!-- Database Property --> <bean id="h2HibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.connection.username">sa</prop> <prop key="hibernate.connection.password"></prop> <prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="h2DataSource"/> </property> <property name="hibernateProperties"> <ref bean="h2HibernateProperties"/> </property> <property name="mappingResources"> <list> <value>com/foo/bar/User.hbm.xml</value> </list> </property> </bean> </beans>


Reply With Quote