-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate 5.2 SchemaUpdate no 'alter table add <column>'
PostPosted: Wed Jun 28, 2017 1:26 am 
Newbie

Joined: Wed Jun 28, 2017 1:13 am
Posts: 1
In my project, previous hibernate version was 4.3.11.Final. After upgrading to 5.2.10.Final, I changed the code as follows and now my schema diff method acts as create settings. I'm using Oracle12c. I both checks Oracle10gDialect and Oracle12cDialect.

I have a spring bean class called HibernatePersistorService. Some parts of this class:

Code:
public class HibernatePersistorService {

  private Metadata metaData;
  private SessionFactory sessionFactory;
  private List<Class> entities;

  ...

  @Override
  public void init() {

    String username = ConfigUtil.getString(true, getConfig("db.username"));

    MapBuilder<String, Object> settingsBuilder = new MapBuilder<String, Object>(new HashMap<>())
        .put("hibernate.dialect", ConfigUtil.getString(true, getConfig("db.dialect")))
        .put("hibernate.connection.driver_class", ConfigUtil.getString(true, getConfig("db.driver")))
        .put("hibernate.connection.url", ConfigUtil.getString(true, getConfig("db.url")))
        .put("hibernate.connection.username", username)
        .put("hibernate.connection.password", ConfigUtil.getString(getConfig("db.password"), ""))
        .put("hibernate.show_sql", ConfigUtil.getString(getConfig("db.showSQL"), "false"));

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
    StandardServiceRegistry serviceRegistry = serviceRegistryBuilder
        .applySettings(settingsBuilder.get())
        .configure("hibernate.cfg.xml")
        .build();

    MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    entities.forEach(metadataSources::addAnnotatedClass);

    metaData = metadataSources.buildMetadata();
    SessionFactoryBuilder sessionFactoryBuilder = metaData.getSessionFactoryBuilder();

    sessionFactory = sessionFactoryBuilder.build();

    logger.info("HibernatePersistorService init()");
  }

  ...

  @Override
  public void generateSchemaDiff() {
    SchemaUpdate schemaUpdate = new SchemaUpdate();
    schemaUpdate.setDelimiter(";");
    schemaUpdate.setFormat(true);
    schemaUpdate.execute(EnumSet.of(TargetType.STDOUT), metaData);
  }
}


And my hibernate.cfg.xml:

Code:
<?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>
    <property name="connection.autocommit">false</property>
    <property name="connection.isolation">2</property>
    <property name="connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
    <property name="javax.persistence.validation.mode">NONE</property>

    <property name="jdbc.batch_size">5</property>
    <property name="jdbc.fetch_size">100</property>
    <property name="jdbc.wrap_result_sets">true</property>

    <property name="org.hibernate.envers.audit_table_prefix">a_</property>
    <property name="org.hibernate.envers.audit_table_suffix"/>
    <property name="org.hibernate.envers.revision_field_name">r_num</property>
    <property name="org.hibernate.envers.revision_type_field_name">r_type</property>
</session-factory>
</hibernate-configuration>


Now, after initialization (calling init()), when method generateSchemaDiff() is called, hibernate generates create statements ignoring what is in the database (i.e. it does not generate the diff and the alter table add <column> statements). For example, I have a table t_dmt_user and I added two properties to the class User. The above code generates all the table from scratch instead of generating alter table t_dmt_user add <column> for those two added properties.

Can anyone help me on this matter?


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2 SchemaUpdate no 'alter table add <column>'
PostPosted: Wed Jun 28, 2017 4:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
You should debug and see why Hibernate does that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.