-->
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.  [ 3 posts ] 
Author Message
 Post subject: Create table only once if it doesn't exist with hbm2ddl?
PostPosted: Mon Nov 05, 2007 5:14 pm 
Newbie

Joined: Mon Nov 05, 2007 4:44 pm
Posts: 9
Hibernate version:
3.2.5g

I have an application that use spring to initiate two data sources, one external DB and one embedded DB (Derby) and mapping files external.hbm.xml and embedded.hbm.xml. (Since I'm using spring, I don't have a hibernate.cfg.xml file) For my development, hbm2ddl=create-drop works great for this setup. For production though, the DB should be created only once and data should be retained. To my surprise, hbm2ddl=create will also drop the table content as well. So I am thinking to generate schema using an ant script, which would be executed on external DB before the application starts. The embedded DB on the other hand, it should not require any user setup so I don't think generating schema would be a good idea. So I am wondering if there is any other tools or settings I could use to generate/create table for just once and still retain the data?

Regards,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 2:11 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
AFAIK not using Hibernate.
You're probably going to have to write something yourself that checks whether the tables exist and creates them if not (of course you'll also have to check whether the database exists...).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 8:57 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Try with hbm2ddl=update
This will update the schema as best as possible to match the mapping files. I say "as best as possible" because certain changes can't be applied. Consider adding a not-null to a column in the mapping file when nulls apready exist in the database data.


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