[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5665) Allow schema/catalog creation/dropping along the lines of AuxiliaryDatabaseObject
Christian Bauer (JIRA)
noreply at atlassian.com
Fri Dec 2 04:03:22 EST 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44493#comment-44493 ]
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
More information about the hibernate-issues
mailing list