Hi.
I have a set of tables, where some correspond to uml classes, and some to associations. The complete database structure contains foreign keys to link the the tables together on a database level. The tables are created through an import.sql script at startup, into an empty db. My question is: How do I map this in Hibernate?
------------------ FK ----------------------- FK ------------------ | ClassTable1| <-------|AssociationTable|------->| ClassTable2 | ------------------ ----------------------- ------------------
I first tried a property mapping in the associations tables, to each of the classes, but that did not work (no surprise).
Then i tried mapping it using many-to-one in the association table, something like this:
<many-to-one name="classtable" column="class1Id" class="Class1"/>
This should make me able to traverse from an association to each of the classes in it? (But not the other way)
Problem is when i run this, and try to run the import script, i get an error message saying that some table already exists. Does this mean that a mapping like this will create a table if one does not exist? Do I need to change the CREATE TABLE statements in the import.sql script to ALTER TABLE statements instead? Or do i even need to run the import.sql script to create the tables, if all the information is in the mappings?
- Tobb
Edit: Found that this last problem was due to the hibernate.hbm2ddl.auto being set to create. But this is a prerequisite for being able to input the import.sql script at startup? So if it is create/create-drop, i get an error because of double definition of tables when import.sql is run, if it is something else it doesn't read import.sql at all?
|