-->
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.  [ 6 posts ] 
Author Message
 Post subject: Drop and re-create the database schema on startup
PostPosted: Wed Jan 17, 2007 7:40 am 
Newbie

Joined: Fri Dec 29, 2006 2:28 pm
Posts: 11
Hibernate version: 3.1.3

Mapping documents: hibernate.cfg.xml

Code:
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>


Name and version of the database you are using: PostgreSQL 8.2

Hi everybody!
I have a class that load the data into the database and another one that looks into it and shows the data. When I run the first one, hbm2ddl.auto property is as above. When I run the second one, I must delete that cfg entry, otherwise my program drops the table, re-creates it (empty) and shows nothing (of course).

My question is:

Is it necessary for me to change everytime the config file or is there another way???

_________________
F/\B!O


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 8:01 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Not, you can do it programatically. See:

http://www.hibernate.org/hib_docs/v3/re ... ogrammatic

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 11:08 am 
Newbie

Joined: Fri Dec 29, 2006 2:28 pm
Posts: 11
Yes, but I can't figure out how to use this info...
Can you post some code, please?
Thanx in advance...

_________________
F/\B!O


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 11:13 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
What do you exactly want to do?

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 12:10 pm 
Newbie

Joined: Fri Dec 29, 2006 2:28 pm
Posts: 11
SpectraLoader.java loads spectra into the db, SpectraView.java lists spectra already in the db. If I run SpectraLoader, then SpectraView, my table SPECTRA is created and populated by SpectraLoader, then recreated and printed (nothing!) by SpectraView ;-(
I would insert some lines of code into SpectraView to check if the table SPECTRA already exists. If no, create, if yes, update. I'm not able...
If you need, I'll post all my code.

_________________
F/\B!O


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 12:23 pm 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Well, i do not think you need to re-create de table each time. Run the app once with <property name="hbm2ddl.auto">create</property> so the tables are created, and then comment out that property from the hibernate cfg file. If you need fresh data every time, delete all rows from the table before inserting the new data...

_________________
andresgr (--don't forget to rate)


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