1

The hibernate.hbm2ddl.auto="update"property is not doing changes in table after changes done in Entity class.

First I have created an Entity as follows

@Entity
@Table(name="EMPLOYEE_SB")
public class Employee {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="EMP_ID")
    private int empId;

    @Column(name="EMP_NAME")
    private String empName;

    //Getter Setter
}

After running application table creation done successfully

Hibernate: create table EMPLOYEE_SB (EMP_ID number(10,0) not null, EMP_NAME varchar2(255 char), primary key (EMP_ID))

Now I have added new field in Entity class as follows

@Entity
@Table(name="EMPLOYEE_SB")
public class Employee {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="EMP_ID")
    private int empId;

    @Column(name="EMP_NAME")
    private String empName;

    @Column(name="PHONE")
    private String phone;

    // Getter and Setter
}

This time the application throw an exception

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:524)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:470)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:273)
    at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:203)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:110)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
    at com.hibernate.app.HibernateUtil.getSessionFactory(HibernateUtil.java:57)
    at com.hibernate.app.MainTestApp.main(MainTestApp.java:8)
Caused by: java.sql.SQLException: ORA-00955: name is already used by an existing object

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:210)
    at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:961)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1190)
    at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1726)
    at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1696)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
    ... 12 more
Sunil Singh Bora
  • 771
  • 9
  • 24
  • Your problem looks like related to [Oracle](http://stackoverflow.com/questions/25993456/ora-00955-name-is-already-used-by-an-existing-object). Not to Hibernate `hibernate.hbm2ddl.auto` option, which apparently, is working as expected. – acm Jan 24 '17 at 07:33
  • 1
    Is there a hibernate statement in the log that precedes this exception? – veljkost Jan 24 '17 at 08:16
  • @veljkost here is it Hibernate: create table EMPLOYEE_SB (EMP_ID number(10,0) not null, EMP_NAME varchar2(255 char), PHONE varchar2(255 char), primary key (EMP_ID)) Jan 24, 2017 12:44:26 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement – Sunil Singh Bora Jan 24 '17 at 08:19
  • It has not created an update script, as docs would suggest. Instead it created a new CREATE TABLE, which obviously already exists.. Maybe you should try `create-drop` option for development. And certainly try out tools like `liquibase` or `flyway` as a way to go. – veljkost Jan 24 '17 at 08:24
  • Are you deploying a webapp in a container? Is it GlassFish? if it's so, that's the problem: some application servers will take care of DDL, understanding only standard values `javax.persistence.schema-generation.database.action` : `none, create, drop-and-create, drop` – Michele Mariotti Jan 24 '17 at 09:46
  • 1
    Nope, I saw from the stacktrace you're running standalone. The problem should be elsewhere. – Michele Mariotti Jan 24 '17 at 09:48

0 Answers0