开发者

DDL scripts with JPA?

开发者 https://www.devze.com 2023-02-21 14:25 出处:网络
So far i\'ve been testing my JPA entities (with Hibernate 3.6.x as the implementation) with the schema being autogenerated with this configuration of hibernate.hbm2ddl.auto being set to create-drop:

So far i've been testing my JPA entities (with Hibernate 3.6.x as the implementation) with the schema being autogenerated with this configuration of hibernate.hbm2ddl.auto being set to create-drop:

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="id.co.sofcograha.erp3" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="false" />
            <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
        </props>
    </property>
</bean>

Now i would like to skip the schema being autogenerated, and would like to manage the schema my开发者_运维技巧self.

But i wonder if i can somehow get the schema autogenerated by hibernate in form of a plain text script file ?

This would ease me since i dont need to create the DDL starting from scratch, but rather, making use of the hibernate-generated-one, and i could just modify some stuffs like the varchar length, column type, etc from the generated file ?

So, in short, what i have in mind is :

  1. create the JPA entities
  2. generate the schema DDL script using hibernate
  3. modify the DDL script to suit my needs
  4. run the modified DDL script
  5. test my entity and application with the new DDL tables

And is my approach a good idea, or you could suggest better approaches ?

Thank you !


Some databases have native tools to reverse engineer a database, pg_dump for PostgreSQL or db2look for DB2, for example. And there is Liquibase, which can help you analyzing and maintaining schemas as they evolve.

0

精彩评论

暂无评论...
验证码 换一张
取 消