-->
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.  [ 5 posts ] 
Author Message
 Post subject: hibernate.hbm2ddl.auto=create-update ??
PostPosted: Sat Jul 24, 2004 3:02 am 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
In my hibernate.properties file, I have been using:

Code:
hibernate.hbm2ddl.auto=create


Of the possible (update, create and create-drop) options, this seemed like the best one to use to ensure my HSQL database was started automagically. This allows me to create a sample app where users don't have to install/start the database manually.

This has been working, but it blows away the database b/w unit test methods and when I restart Tomcat. I expected this.

Tonight, I tried changing the value to "create-update" because this is the behavior I really want: create the database if it doesn't exist, update the schema if I change any mapping files, don't delete the data.

I don't know if its a miracle or what, but it works! Is this Colorado beer getting to me, or is this a hidden Hibernate feature?

I'm using Hibernate 2.1.4, Spring 1.1 RC1-dev (last night), Tomcat 5.0.27, Ant 1.6.2, Cygwin on Windows XP - powered by JDK 1.4.2.

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 24, 2004 8:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Here is the relevant code from SettingsFactory:

Code:
      String autoSchemaExport = properties.getProperty(Environment.HBM2DDL_AUTO);
      if ( "update".equals(autoSchemaExport) ) settings.setAutoUpdateSchema(true);
      if ( "create".equals(autoSchemaExport) ) settings.setAutoCreateSchema(true);
      if ( "create-drop".equals(autoSchemaExport) ) {
         settings.setAutoCreateSchema(true);
         settings.setAutoDropSchema(true);
      }


So no, create-update is no hidden feature, it actually should not work at all. I find it pretty mysterious that it works :)

However just "update" should do exactly what you want, create the tables if nothing is there, update them otherwise. Note that the "update" part is not really maintained anymore however.


Top
 Profile  
 
 Post subject: "update" works
PostPosted: Sat Jul 24, 2004 4:03 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
Using "update" seems to give me the same behavior as "create-update", so I'll go with that.

Quote:
Note that the "update" part is not really maintained anymore however.

Are you saying this is not a good option to use? Why isn't it maintained anymore?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 25, 2004 9:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Mostly because of the poor quality of the JDBC driver metadata implementation, which makes it often impossible to figure out the current status of the database. And besides, updating the database to a new schema is difficult to do automatically - what happens to existing data for example.


Top
 Profile  
 
 Post subject: Re: hibernate.hbm2ddl.auto=create-update ??
PostPosted: Thu Sep 03, 2009 5:37 pm 
Newbie

Joined: Thu Aug 27, 2009 2:12 pm
Posts: 7
Hey guys,

I am having the same problem here. with create-update my schema is blown away each time and that is unacceptable. A much sounder approach would be to create if not there, update if it is.

This is how I would expect a real application to function.

create seems like it only makes sense for certain kind of development....thus I do not understand the purpose of create-update.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.