How to execute differnet import.sql in Hibernate/JPA for each persistence unit?

跟風遠走 提交于 2019-11-30 07:45:15

You could probably do something manual using the org.hibernate.tool.hbm2ddl.SchemaExport class when your application starts up.

SchemaExport schemaExport1 = new SchemaExport(cfg1); // there are various c-tors available
schemaExport1.setInputFile("/import-1.sql");
schemaExport1.create(false, true);

SchemaExport schemaExport2 = new SchemaExport(cfg2);
schemaExport2.setInputFile("/import-2.sql");
schemaExport2.create(false, true);

FWIW, this is possible with Hibernate 3.6.0.Beta1 (see HHH-5337), you can now declare what file(s) to import using the hibernate.hbm2ddl.import_files property:

hibernate.hbm2ddl.import_files /mydbload.sql,/mydbload2.sql

So you could use different values for each persistence unit.

In all my projects, i use only one import.sql and next to it i create different other *.sql(eg : H2_import.sql,sqlServer_import.sql) and depending on wich persistence unit to use i copy the content of *.sql and past it into import.sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!