to update the schema every time the application context loads just set the schemaUpdate property on your LocalSessionFactoryBean to true.
If you only want to update it occasionally rather than every time the context loads then using a system proprety is one way to do it:
Code:
<bean id="sysProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System" />
<property name="targetMethod" value="getProperties" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingLocations" value="classpath*:**/*.hbm.xml" />
<property name="hibernateProperties">
<map>
<entry key="hibernate.dialect" value="${hibernate.dialect}" />
</map>
</property>
<property name="schemaUpdate">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="sysProps" />
<property name="targetMethod" value="getProperty" />
<property name="arguments">
<list>
<value>hibernate.schemaUpdate</value>
<value>false</value>
</list>
</property>
</bean>
</property>
</bean>
Code:
public class SchemaUpdater {
public static void main(String[] args) {
System.setProperty("hibernate.schemaUpdate", "true");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {
"applicationContext.xml" });
context.close();
}
}