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

3

2

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.

Campeche answered 12/4, 2009 at 16:24 Comment(0)
B
5

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);
Brandish answered 13/4, 2009 at 1:33 Comment(1)
The method is called SchemaExport.setImportFile(String)Afterpiece
C
7

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.

Catamaran answered 28/10, 2010 at 23:17 Comment(0)
B
5

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);
Brandish answered 13/4, 2009 at 1:33 Comment(1)
The method is called SchemaExport.setImportFile(String)Afterpiece
S
0

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

Salutation answered 28/2, 2013 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.