wood burning stoves*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Why Hibernate SchemaUpdate is creating new field instead of updating? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Why Hibernate SchemaUpdate is creating new field instead of updating?" Watch "Why Hibernate SchemaUpdate is creating new field instead of updating?" New topic
Author

Why Hibernate SchemaUpdate is creating new field instead of updating?

Milind Bharambe
Greenhorn

Joined: Apr 03, 2012
Posts: 4
I am trying to update the existing schema programmatically using SchemaUpdate. I changed the name of the existing field name in specific table and then, I am creating the hibernate configuration object and adding the changed hbm.xml files into the configuration object.

But when I said SchemaUpdate.execute(true,true) it is creating the new field in the table instead of updating.

Here is my code:

Configuration hibConfiguration = new Configuration();
hibConfiguration.configure(configFileDoc);
hibConfiguration.addDocument(doc1);
hibConfiguration.addDocument(doc2);

hibConfiguration.buildMappings();
SchemaUpdate schemaUpdate = new SchemaUpdate(hibConfiguration);
schemaUpdate.execute(true, true);

following is my cfg.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">passwrd</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhot:3306/testSchema</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="javax.persistence.validation.mode">none</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.default_entity_mode">dynamic-map</property>
</session-factory>
</hibernate-configuration>

and this is my hbm.xml file for table to update:

<?xml version="1.0" encoding="UTF-8"?><hibernate-mapping>
<class entity-name="testTable2">
<id column="id" name="id" type="java.lang.Long">
<generator class="identity"/>
</id>
<property column="testTable1Id" length="20" name="testTable1Id" type="java.lang.Long"/>
<property column="doubleColumnj" length="20" name="doubleColumnj" type="java.lang.Double"/>
</class>
</hibernate-mapping>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Hibernate SchemaUpdate is creating new field instead of updating?