如何在每个持久性单元的Hibernate / JPA中执行不同的import.sql? [英] How to execute differnet import.sql in Hibernate/JPA for each persistence unit?

查看:597
本文介绍了如何在每个持久性单元的Hibernate / JPA中执行不同的import.sql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JPA / Hibernate配置中配置了两个持久化单元。现在我需要为每个持久性单元执行不同的import.sql。我如何指定为每个持久性单元执行哪个import.sql?根据Hibernate的文档,我应该将import.sql放在classpath中。如果我这样做,import.sql将在每个持久性单元上执行。我需要以某种方式为每个持久性单元指定不同的import.sql。

I have configured two persistence units in my JPA/Hibernate configuration. Now i need to execute different import.sql for each persistence unit. How can I specify which import.sql should be executed for each persistence unit? According Hibernate to documentation, I should place import.sql in classpath. If I do that, import.sql is executed on each persistence unit. I need somehow to specify different import.sql for each persistence unit.

推荐答案

你可以使用org.hibernate .tool.hbm2ddl.SchemaExport类,当你的应用程序启动时。

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);

这篇关于如何在每个持久性单元的Hibernate / JPA中执行不同的import.sql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆