我在 JPA/Hibernate 配置中配置了两个持久性单元。现在我需要为每个持久性单元执行不同的 import.sql。如何指定应为每个持久性单元执行哪个 import.sql?根据 Hibernate 文档,我应该将 import.sql 放在类路径中。如果我这样做,import.sql 会在每个持久性单元上执行。我需要以某种方式为每个持久性单元指定不同的 import.sql。
问问题
8025 次
3 回答
7
FWIW,这在 Hibernate 3.6.0.Beta1 中是可能的(参见HHH-5337hibernate.hbm2ddl.import_files
),您现在可以使用属性声明要导入的文件:
hibernate.hbm2ddl.import_files /mydbload.sql,/mydbload2.sql
因此,您可以为每个持久性单元使用不同的值。
于 2010-10-28T23:17:51.757 回答
5
当您的应用程序启动时,您可能可以使用 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);
于 2009-04-13T01:33:30.350 回答
0
在我所有的项目中,我只使用一个 import.sql,然后在它旁边创建不同的其他 *.sql(例如:H2_import.sql,sqlServer_import.sql),并根据要使用的持久性单元复制 *.sql 的内容并将其传递到 import.sql
于 2013-02-28T11:43:18.773 回答