• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Hibernate SchemaUpdate is creating new field instead of updating?

 
Milind Bharambe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic