Dan*_*Dan 2 import hibernate jpa persistence-unit
我在JPA/Hibernate配置中配置了两个持久性单元.现在我需要为每个持久性单元执行不同的import.sql.如何指定应为每个持久性单元执行哪个import.sql?根据Hibernate的文档,我应该将import.sql放在classpath中.如果我这样做,import.sql将在每个持久性单元上执行.我需要以某种方式为每个持久性单元指定不同的import.sql.
FWIW,这可以通过Hibernate 3.6.0.Beta1(参见HHH-5337)实现,您现在可以使用hibernate.hbm2ddl.import_files属性声明要导入的文件:
hibernate.hbm2ddl.import_files /mydbload.sql,/mydbload2.sql
Run Code Online (Sandbox Code Playgroud)
因此,您可以为每个持久性单元使用不同的值.
在应用程序启动时,您可以使用org.hibernate.tool.hbm2ddl.SchemaExport类手动执行某些操作.
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7950 次 |
| 最近记录: |