Personally, I love using the SchemaExport class. It's got a very simple create method:
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=02validatingthehibernateenvironment
Quote:
public void create(boolean script, boolean export)
Run the schema creation script.
Parameters:
script - print the DDL to the console
export - export the script to the database
THe code for running it couldn't be easier:
Code:
public static void main(String args[]) {
AnnotationConfiguration config =
new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
config.configure();
new SchemaExport(config).create(true, true);
}
You just need to ensure you have a valid AnnotationConfiguration/Hibernate Configuration object initialized properly and you're set.

Here's a full Java class that has a main method which creates a database table to manage the persistent state of the POJO:
Code:
package com.examscam.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@Entity
public class User {
private Long id;
private String password;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public static void main(String args[]) {
AnnotationConfiguration config =
new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
config.configure();
new SchemaExport(config).create(true, true);
}
}
Here's the full tutorial from my website:
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=02validatingthehibernateenvironment