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 :
- create the JPA entities
- generate the schema DDL script using hibernate
- modify the DDL script to suit my needs
- run the modified DDL script
- 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.
精彩评论