I am working with Hibernate on Java with a MySQL database. If I set hbm2ddl.auto to create, all current tables are dropped and recreated correctly, but if I set it to update, it does nothing to the database despite reporting the following line to the console:
INFO: HHH000228: Running hbm2ddl schema update
For reference, the code I am using to set up the database is:
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure()
.build();
While my cfg.xml file looks like:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/testdatabase</property>
<property name="connection.username">xxxxxxxx</property>
<property name="connection.password">xxxxxxxx</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!-- Names the annotated entity class -->
<mapping class="com.test.case.Example"/>
</session-factory>
</hibernate-configuration>
Obviously, since the create is working, I see no need to show my annotated class.
EDIT:
The changes I expect to happen are basically to correct the database column types to the correct ones. Before running the update, I changed the column types in MySQL to something different from the annotated schema, but on update, Hibernate is not correcting them as it would be expected. In contrast, when I dropped the table altogether, the update did work. It would seem the update is not fully featured as expected?
updatei think it will create the tables.