-->
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: sql script generation
PostPosted: Tue Jul 22, 2008 5:54 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 statements (the table definitions) on creation??
is there any way to do that in hibernate?
Generate the sql script for tables creation ?and if this available can i do it - generate the sql creation table statements - to a file?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 9:49 am 
Newbie

Joined: Wed Jun 18, 2008 9:07 am
Posts: 6
plz it is argent ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 10:00 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Use the Hibernate SchemaExport class. It will create scripts like this:

Code:
drop table if exists User
create table User
(id integer not null auto_increment,
password varchar(255),
primary key (id))



It's easy to use if you have a Configuration object already configured, and you can control it programatically. Here's a tutorial I put together on verifying your Hibernate3 configuration with the SchemaExport:

http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=02validatingthehibernateenvironment



Code:
  public static void main(String args[]) {
    AnnotationConfiguration config =
                 new AnnotationConfiguration();
    config.addAnnotatedClass(User.class);
    config.configure();
    new SchemaExport(config).create(true, true);
  }


Image

Here's the Hibernate tutorial link from which this code originates. Check it out!



[url]
http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=02validatingthehibernateenvironment[/url]

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 23, 2008 7:51 am 
Newbie

Joined: Wed Jun 18, 2008 9:07 am
Posts: 6
Thaaaaaaaaaaaaaanks alot
this is really helped


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 12:09 pm 
Newbie

Joined: Thu Mar 17, 2005 2:06 pm
Posts: 12
Yes, you can have the sql statements put into a file, as well as hbm files. There are many tools, like the one listed above. I like http://www.javatosql.com because it analyzes your Java objects and creates everything from that. You don't need to write additional code to get the sql or schema.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 9:01 am 
Newbie

Joined: Wed Jun 18, 2008 9:07 am
Posts: 6
hi Mr.Cameron McKenzie
I noticed that i can generate the sql script using:
AnnotationConfiguration config =
new AnnotationConfiguration();
config.configure();
new SchemaExport(config).setOutputFile("output").create(true,false);


i don't have to add annotations to my classes and i don't have to use
config.addAnnotatedClass(user.class);

Can I know plz what are the uses of these annotations ??and the use of using
config.addAnnotatedClass(user.class);


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.