-->
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: Create SQL script from classes with annotations
PostPosted: Fri Jul 11, 2008 3:50 am 
Newbie

Joined: Thu Jun 26, 2008 9:36 am
Posts: 10
Hi,

I'm using Eclipse and I have classes with annotations. I want to get the script SQL to create the database, but don't find out how do that.

Could someone tell me how or show me a link to do that please ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 5:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

there are several ways to do that, depending on what you are trying to achieve.

You can add the property hbm2ddl.auto to your hibernate configuration file and set it to create. This way the schema gets generated whenever Hibernate starts.

You can also do it programmatically:
Code:
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Foo.class);
...
config.buildSessionFactory();
String[] schema = config.generateSchemaCreationScript(new MyDialect());


Last but not least you can generate the schema as part of the build using ant or some Eclipse Hibernate plugin.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 6:02 am 
Newbie

Joined: Thu Jun 26, 2008 9:36 am
Posts: 10
Thank you, that is what I was looking for.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 4:20 am 
Newbie

Joined: Wed Jun 18, 2008 9:07 am
Posts: 6
is there a way i can generate sql script??
where do i get the out put?
can i have it on a file?

plz i am new to hibernate and i need to generate the sql script to a file??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 5:43 am 
Newbie

Joined: Wed Jun 18, 2008 9:07 am
Posts: 6
The show_sql shows the sql statements but doesn't show the Create Table statement (the table definetions) ??
is there any way to do that in hibernate?


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.