-->
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.  [ 4 posts ] 
Author Message
 Post subject: Issues with hibernate.hbm2dll.auto
PostPosted: Wed Oct 25, 2006 7:43 am 
Newbie

Joined: Thu Jun 09, 2005 6:41 am
Posts: 10
Hi,

We are facing a dire need here. Our Entity bean structures are changing often. We either add new classes or new variables to existing classes.

We have enough test data already inserted into the database.

When we build the session factory during each run, we tried all these options but we face some problem or the other, since we want the new changes reflected in the database structure and yet RETAIN the existing data.

hibernate.hbm2dll.auto:
create-drop is a bad idea as it deletes all the data but creates all the required tables
create again seems to delete all the data
update retains the data AND creates new columns (i think) for new variables in existing tables BUT does not seem to create the new tables when new classes are introduced.

is it possible for us to have 'update' create new variables/columns in exsiting classes/tables and add new classes/tables
OR
have create not drop existing data

Rahul


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 8:43 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Are you sure that hbm2ddl.auto=update does not produce what you want? Here is the hibernate code related to that
Code:
            TableMetadata tableInfo = databaseMetadata.getTableMetadata(
                  table.getName(),
                  table.getSchema(),
                  table.getCatalog()
               );
            if ( tableInfo == null ) {
               script.add(
                     table.sqlCreateString(
                           dialect,
                           mapping,
                           defaultCatalog,
                           defaultSchema
                        )
                  );
            }
            else {
               Iterator subiter = table.sqlAlterStrings(
                     dialect,
                     mapping,
                     tableInfo,
                     defaultCatalog,
                     defaultSchema
                  );

Reading that indicates that there shoul dbe a create/alter sql depending on whether it exists or not. Are you including the class/resource(hbm.xml) in the mapping file ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 2:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
note that schemaupdate does not handle all situations since sometimes they are not possible to do without additional info (e.g. going from null to not null what should the existing null values be changed to ?)

That is why having migration scripts are a Good Thing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 4:06 pm 
Newbie

Joined: Thu Jun 09, 2005 6:41 am
Posts: 10
Thanks for your response. Here is the code that I have written so far :

Code:
cfg.setProperty("hibernate.dialect", PostgreSQLDialect.class.getName());
cfg.setProperty("hibernate.connection.url", url);
cfg.setProperty("hibernate.connection.username", username);
cfg.setProperty("hibernate.connection.password", password);
cfg.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
cfg.setProperty("dbLargeBinaryType", "binary");
cfg.setProperty("hibernate.c3p0.min_size", "1");
cfg.setProperty("hibernate.c3p0.max_size", "10");
cfg.setProperty("hibernate.c3p0.timeout", "1800");
cfg.setProperty("hibernate.c3p0.max_statements", "50");
cfg.setProperty("hibernate.statement_cache.size", "100");
cfg.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
if (recreateNewDatabase) {
   cfg.setProperty("hibernate.hbm2ddl.auto", "create-drop");
} else
   cfg.setProperty("hibernate.hbm2ddl.auto", "update");
sf = cfg.buildSessionFactory();


We use "create-drop" during fresh-groundup test mode and use "update" during other brief testing modes (that is when we want to retain the same data while we make changes to value objects and re run our applications).

Again, my thinking is that incase we are using "update" mode, then:
1: New Columns will be created, when new Variables are introduced
2: New tables will be created when new classes are introduced
3: Updating / Deleting variable names, not nulls to nulls etc etc should not result in any changes in database, as it would be tough for hibernate to recognize what got changed from past to present. I can understand this limitation.

But atleast #1 and #2 should reflect in update which would help users to to retain the existing data and get into a higher productivity mode.

Is there anyway any one can help me please?
Rahul


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.