Java: Creating scripts from Hibernate model classes
This main method shows how get scripts created by Hibernate
import org.hibernate.cfg.Configuration; import org.hibernate.dialect.MySQLDialect; import com.globallogic.volokh.beans.Authority; import com.globallogic.volokh.beans.Contact; /** * @author danylo.volokh * * This class is made to get Creation schema script generated by * Hibernate. Need this dependency * ** * */ public class HibernateScriptCreator { public static void main(String[] args) { Configuration cfg = new Configuration(); // add classes that are models and add Dialect depends witch DB are used cfg.addAnnotatedClass(Authority.class); cfg.addAnnotatedClass(Contact.class); String[] lines = cfg.generateSchemaCreationScript(new MySQLDialect()); System.out.println(lines); System.out.println(lines.length); for (int i = 0; i < lines.length; i++) { System.out.println(lines[i] + ";"); } } }org.hibernate.common *hibernate-commons-annotations *4.0.1.Final *
0 Comments