I try to build a new database from scratch in a two step process :
1)Generate DDL with SchemaExport based on a few *.hbm.xml files
2)Build the database based on the DDL from the previous step
However, the DDL generated cannot be run in step 2, as is quite obvious when you look into the generated file (some statements omitted for clarity):
____________
alter table many_to_many_relation_table drop constraint FKB8C019B364057B70;
drop table many_to_many_relation_table if exists;
create table many_to_many_relation_table .............................
alter table many_to_many_relation_table add constraint FKB8C019B364057B70 foreign key (aId) references tableX;
alter table many_to_many_relation_table add constraint FKB8C019B3C042B583 foreign key (bId) references tableY;
_____________
In the first statement, there is an alter table statement that refers to a table that does not (yet) exist in the scenario of creating a db from scratch. Consequently, I cannot find a way to generate the DB based on the DDL in my step 2 (executing a SQL statement at the time)
However, if I reconsider my strategy and do it all in ONE operation using SchemaExport it works fine. It seems there is quite some magic going on when "SchemaExporting" to the db. So there are two cases:
a)let schemaexport target the db directly
b)take the ddl generated by schemaexport and run it against the database
Why isn't case a) and b) equivalent?
As b) does not work, what is the point in exporting the DDL to console or file? debugging? information?
Furthermore, if the ALTER TABLE ..DROP CONSTRAINT had been omitted, it would have worked just fine. Why is those included (the tables involved are droppen anyway)?
Currently it looks I will have to reimplement a slightly different schemaexport ant task to support my scenario, which doesn't feel good.
Have anybody been down this road?
|