亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 Hibernate 升級到 5.4.1 后如何導出架構?

將 Hibernate 升級到 5.4.1 后如何導出架構?

萬千封印 2022-06-30 10:38:02
我最近將 Hibernate 從 4.3.7 更新到 5.4.1,并且SchemaExport自 5.1 以來 API 發生了變化。此代碼現在顯示編譯問題(在SchemaExport構造函數和execute方法上)。/** * Method to generate a SQL script which aim is to create SQL tables for the * entities indicated as parameters. */private void generateScript(Class<?>... classes) {    Configuration configuration = new Configuration();    configuration.setProperty(Environment.DIALECT, entityManagerFactory.getProperties().get(DIALECT_PROPERTY).toString());    for (Class<?> entityClass : classes) {        configuration.addAnnotatedClass(entityClass);    }    SchemaExport schemaExport = new SchemaExport(configuration);    schemaExport.setDelimiter(SCRIPT_DELIMITER);    schemaExport.setOutputFile(getScriptPath());    schemaExport.setFormat(true);    boolean consolePrint = false;    boolean exportInDatabase = false;    schemaExport.execute(consolePrint, exportInDatabase, false, true);}我已經看到與此問題相關的其他問題,但沒有足夠具體的內容來幫助我重寫此函數。
查看完整描述

1 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

這是我所做的并且有效:


private void genererScript(Class<?>... classes) {


    StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()

            .applySetting(Environment.DIALECT, entityManagerFactory.getProperties().get(DIALECT_PROPERTY).toString())

            .build();


    MetadataSources sources = new MetadataSources( standardRegistry );

    for (Class<?> entityClass : classes) {

        sources.addAnnotatedClass(entityClass);

    }


    MetadataImplementor metadata = (MetadataImplementor) sources

            .getMetadataBuilder()

            .build();


    EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);


    try {

        Files.delete(Paths.get(getScriptPath()));

    } catch (IOException e) {

        /*

         * The file did not exist...

         * we do nothing.

         */

    }


    SchemaExport schemaExport = new SchemaExport();

    schemaExport.setDelimiter(SCRIPT_DELIMITER);

    schemaExport.setOutputFile(getScriptPath());

    schemaExport.setFormat(true);

    schemaExport.createOnly(targetTypes, metadata);

}


查看完整回答
反對 回復 2022-06-30
  • 1 回答
  • 0 關注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號