Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernateJpaVendorAdapter's generateDdl doesn't alter tables
    primarykey
    data
    text
    <p>I am developing a website using Spring+JPA+Hibernate. In the persistence configuration (JPA+Hibernate) I'm setting the HibernateJpaVendorAdapter's generateDdl attribute to true and in fact new entities correctly create the new table in the DB.</p> <p>Once the table has been created, though, if I add an attribute to the entity, I'm expecting the HibernateJpaVendorAdapter to alter the table and add the column as well. This is not happening and it's strange because in the Java AbstractJpaVendorAdapter's setGenerateDdl method documentation there is: "Set whether to generate DDL after the EntityManagerFactory has been initialized, creating/<strong>updating</strong> all relevant tables."</p> <p>JPA+Hibernate configuration:</p> <pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${db.driverClassName}" /&gt; &lt;property name="url" value="${db.url}" /&gt; &lt;property name="username" value="${db.username}" /&gt; &lt;property name="password" value="${db.password}" /&gt; &lt;/bean&gt; &lt;bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt; &lt;property name="showSql" value="${db.showSql}" /&gt; &lt;property name="generateDdl" value="${db.generateDdl}" /&gt; &lt;/bean&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="jpaVendorAdapter" ref="jpaAdapter" /&gt; &lt;property name="jpaProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;/bean&gt; </code></pre> <p>persistence.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt; &lt;persistence-unit name="m8tsPU" /&gt; &lt;/persistence&gt; </code></pre> <p>Am I doing something wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload