[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5665?page=c...
]
Christian Bauer commented on HHH-5665:
--------------------------------------
There are other database objects besides schemas that have to be created before the tables
are created, e.g. domains. This is my workaround:
{code}
Ejb3Configuration configuration = new Ejb3Configuration();
patchConfiguration(configuration);
protected void patchConfiguration(Ejb3Configuration ejb3Configuration) throws Exception {
Configuration cfg = new Configuration() {
@Override
public String[] generateSchemaCreationScript(Dialect dialect) throws
HibernateException {
List<String> statements = new ArrayList();
statements.addAll(Arrays.asList(super.generateSchemaCreationScript(dialect)));
List<String> beforeTablesStatements = new ArrayList();
Iterator<String> it = statements.iterator();
while (it.hasNext()) {
String statement = it.next().toLowerCase();
if (statement.startsWith("create schema") ||
statement.startsWith("create domain")) {
// Add more "before table DDL" checks here if needed
beforeTablesStatements.add(statement);
it.remove();
}
}
for (String beforeTablesStatement : beforeTablesStatements) {
statements.add(0, beforeTablesStatement);
}
return statements.toArray(new String[statements.size()]);
}
};
Field delegateField =
ejb3Configuration.getClass().getDeclaredField("ejb3EntityNotFoundDelegate");
delegateField.setAccessible(true);
EntityNotFoundDelegate delegate =
(EntityNotFoundDelegate)delegateField.get(ejb3Configuration);
cfg.setEntityNotFoundDelegate(delegate);
Field cfgField = ejb3Configuration.getClass().getDeclaredField("cfg");
cfgField.setAccessible(true);
cfgField.set(ejb3Configuration, cfg);
}
{code}
I suggest adding a simple <database-object
before="tables|identifiers|none"> switch.
Allow schema/catalog creation/dropping along the lines of
AuxiliaryDatabaseObject
---------------------------------------------------------------------------------
Key: HHH-5665
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5665
Project: Hibernate Core
Issue Type: Sub-task
Components: metamodel
Reporter: Steve Ebersole
Fix For: 4.1.0
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira