Search code examples
javasqlhibernategenerated-code

JPA - How to get any produced sql code programmatically?


JPA gurus, let say I have the following entity :

@Entity
class MyEntity {
    @Id
    private Long id;

    // setters and getters here
}

through JPA on an Oracle database something similar would be generated :

CREATE TABLE MyEntity {
    -- table definition generated by JPA provider goes here
}

How can I get the code generated by the JPA provider ?

If it's not possible to get the sql code in a standard way defined by JPA, how can I achieve this with Hibernate 3.6.8.Final or greater ?


Solution

  • Look at classes in hbm2ddl package

    http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/tool/hbm2ddl/package-summary.html

    Especially SchemaExport class.