I have two separate session factories (sf1, sf2) that both load their proper
import.sql during the session factory's initialization (
hibernate.hbm2ddl.auto is set to create). Each session factory resides in its own jar and the test cases work perfectly in an isolated environment.
As soon as both session factories are loaded from the main application, sf2 executes schema export with the contents of sf1's i
mport.sql. Of course that results in an error. I assume this happens because the thread's class loader is used (
import.sql is loaded using
ConfigHelper), but I might be wrong.
An option would be to rename the two
import.sql files to
import_project1.sql and
import_project2.sql, and load them during initialization of the respective session factories. The problem is, I could not find a way to configure the
importFile property in
SchemaExport. I don't see a way to override it using either config or settings. How could I do something like that?
In this project, sf1 is loaded via a managed persistence context in JBoss Seam. sf2 is loaded by Spring using a customized AnnotationSessionFactoryBean. See the error I encounter during the intialization of sf2 below:
Code:
INFO [org.hibernate.tool.hbm2ddl.SchemaExport] Running hbm2ddl schema export
INFO [org.hibernate.tool.hbm2ddl.SchemaExport] exporting generated schema to database
INFO [org.hibernate.tool.hbm2ddl.SchemaExport] Executing import script: /import.sql
ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] schema export unsuccessful
org.hibernate.JDBCException: Error during import script execution
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:258)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:192)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:753)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:691)
…
Caused by: java.sql.SQLException: Table not found in statement [insert into user]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:254)
I hope someone can point me to a way to do that.
Thank you,
Kariem