File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Hibernate SchemaUpdate is creating new field instead of updating?

Milind Bharambe
Posts: 4
  • 0
  • 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();

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

following is my cfg.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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="">update</property>
<property name="hibernate.default_entity_mode">dynamic-map</property>

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"/>
<property column="testTable1Id" length="20" name="testTable1Id" type="java.lang.Long"/>
<property column="doubleColumnj" length="20" name="doubleColumnj" type="java.lang.Double"/>
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic