How to get automatic table creation working in spring / hibernate / jpa? How to get automatic table creation working in spring / hibernate / jpa? spring spring

How to get automatic table creation working in spring / hibernate / jpa?


try the following:

<?xml version="1.0" encoding="UTF-8"?><persistence version="1.0" xmlns="http://java.sun.com/xml/ns/  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://.sun.com/xml/ns/persistence  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">    <persistence-unit name="naveroTest" transaction-type="RESOURCE_LOCAL" /></persistence>
<?xml version="1.0" encoding="UTF-8"?><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">    <property name="jpaVendorAdapter">        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>    </property>    <property name="jpaProperties">        <props>...            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>        </props>    </property>    <property name="dataSource" ref="dataSource" /></bean>

This works for me.


I had exactly the same issue...

Commenting out property

    <!--property name="generateDdl" value="true"--> in the JpaAdapter, 

but setting

<property name="hibernate.hbm2ddl.auto" value="create"/> in persistence.xml 

worked for me. I am using hsqldb.

I noticed in the logs that the mode was beign set to update no matter what I set in persistence.xml.

The value in persistence.xml was actually picked up but never applied.I am using Spring 3.0.6 and Hibernate 4


Can you try changing the generateDdl property to false on HibernateJpaVendorAdapter in your spring config file.

Seems to conflict with the hibernate hibernate.hbm2ddl.auto property

See https://jira.springframework.org/browse/SPR-6836 for more info.