-->
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.  [ 2 posts ] 
Author Message
 Post subject: Programmatic schema generation with HibernateToolTask
PostPosted: Thu Jan 26, 2012 8:36 pm 
Newbie

Joined: Thu Jan 26, 2012 8:00 pm
Posts: 1
Hi, i'm new with Hibernate and i'm looking for a nice way to export my database schema (I used JPA Annotations). I've tried the HibernateToolTask with Ant, and it worked flawlessly. But now i'm wondering if there is a way to use this same tool but from Java code. I've been looking around but i didn't find much about this. Maybe there is another way to do this, or is something useless that only occurred to me and i have to do this from the command line with Ant.
I've tried also with SchemaExport and AnnotationConfiguration, but that way i have to manually put each annotated class.
Looking at the org.hibernate.tool.ant package classes i thought that something like this may work:
Code:
HibernateToolTask hibToolTask = new HibernateToolTask();
Hbm2DDLExporterTask schemaExportTask = (Hbm2DDLExporterTask)hibToolTask.createHbm2DDL();
schemaExportTask.setOutputFileName("schema.sql");
schemaExportTask.execute();
but i was too optimistic.

If someone could help me with this, i would appreciate that.


Top
 Profile  
 
 Post subject: Re: Programmatic schema generation with HibernateToolTask
PostPosted: Fri Jan 27, 2012 7:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Just created a hibernate configuration and would normally and use SchemaExport on it - that is what hibernate tools does anyway, but you don't have to depend on hibernate tools for it.

Dependent on the version of hibernate you can use Ejb3Configuration - but all depends what you want/version you are at to get "classpath" scanning.

You can also take a look at hibernate tools source code for HibernatetoolTask to see how we do it - it's pretty straightforward ;)


https://github.com/hibernate/hibernate- ... lTask.java

_________________
Max
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.  [ 2 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.