ef ddl生成不了脚本_如何使用Hibernate从Play生成DDL脚本! 框架项目
生活随笔
收集整理的這篇文章主要介紹了
ef ddl生成不了脚本_如何使用Hibernate从Play生成DDL脚本! 框架项目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ef ddl生成不了腳本
好的,因此您一直在使用hibernate屬性名稱=“ hibernate.hbm2ddl.auto ” value =“ 更新 ”來不斷更新數據庫模式, 但是現在您需要一個完整的DDL腳本嗎?
從您的Global Class onStart中使用此方法來導出DDL腳本。 只需為其提供實體的包名稱(帶有路徑)以及文件名即可:
public void onStart(Application app) {exportDatabaseSchema("models", "create_tables.sql");}public void exportDatabaseSchema(String packageName, String scriptFilename) {final Configuration configuration = new Configuration();final Reflections reflections = new Reflections(packageName);final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class);// iterate all Entity classes in the package indicated by the namefor (final Class<?> clazz : classes) {configuration.addAnnotatedClass(clazz);}configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");SchemaExport schema = new SchemaExport(configuration);schema.setOutputFile(scriptFilename);schema.setDelimiter(";");schema.execute(Target.SCRIPT, SchemaExport.Type.CREATE ); // just export the create statements in the script}這就對了!
感謝@MonCalamari在這里回答我有關Stackoverflow的問題 。
翻譯自: https://www.javacodegeeks.com/2014/10/how-to-use-hibernate-to-generate-a-ddl-script-from-your-play-framework-project.html
ef ddl生成不了腳本
總結
以上是生活随笔為你收集整理的ef ddl生成不了脚本_如何使用Hibernate从Play生成DDL脚本! 框架项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iqooneo855屏幕是三星的吗
- 下一篇: jax-rs/jersey_使用JAX-