Zum Hauptinhalt gehen

Database METADATA - "Foreign Key" vs. "Create Index"

Kommentare

9 Kommentare

  • Zendesk API User
    Author: feddersen - 8/9/2010 10:29

    Hi Marius,

    which FirstSpirit and Oracle version are you using?

    Christoph

    0
  • Zendesk API User
    Author: marius - 8/9/2010 11:30

    FirstSpirit Client 4.2.219.38784

    Oracle 11g

    0
  • Zendesk API User
    Author: feddersen - 8/9/2010 14:53

    You correct that FirstSpirit 3.x used foreign keys. That behaviour has been changed with FirstSpirit 4.x, for reasons I do not know yet. It should be save to define the foreign keys manually, we already did that.

    Btw Oracle11g isn't officially supported at the moment, but will be with FirstSpirit 4.2R4.

    0
  • Zendesk API User
    Author: marius - 8/9/2010 15:17

    Oracle 11g / Oracle 10g ... same thing from this discussion point of view.

    Manually setting up the Foreign-key for a large number of tables (80 - 100) in about 50 schemas ... I don't think is a good idea.

    0
  • Zendesk API User
    Author: feddersen - 8/9/2010 15:29

    You could do it the other way round. Create all schemas with an external tool, connect them to FirstSpirit and enable schema syncing. It may preserve the foreign keys then. Might be worth a try.

    Please keep in mind that this information might be lost during a normal project import/export. You can work around that by copying the database yourself.

    0
  • Zendesk API User
    Author: marius - 8/9/2010 15:36

    I don't think this is a good approach, since there will be different strategies for:

    - primary keys,

    - relations (especially for the many to many relations)

    - special fields names (for example FS uses the VERSION field name, which some databases don't allow it - since it is a pre-reserved name);

    - sequence Id strategy

    0
  • Zendesk API User
    Author: feddersen - 8/10/2010 21:36

    A clean approach would be to extend the reverse engineering code to check for the indices instead of foreign keys. I don't know what tool you're using, but Hibernate does allow that with a custom reverse engineering strategy. It shouldn't be much work if you're using the  DelegatingReverseEngineeringStrategy class. Implementing the methods that deal with foreign keys should be enough.

    0
  • Zendesk API User
    Author: marius - 8/11/2010 8:04

    Thanks for your answer.

    I already extended/customized/patched the hibernate-tools which I use it for reverse engineering.

    The biggest issue is related to the fact that there are no foreign keys defined between tables that have relations defined.

    Even if I want to define/add the Foreign-Key at the database level by including the First Spirit field (<shortened table name>_FS_ID), this wouldn't work because in the primary key are used timestamps. Just imagine there is a PARENT(1) - (*)CHILDREN relation between the two tables, where the parent record has 3 children related records. Because of the timestamps (which are different for each record from the two tables) the foreign key will not work.

    Also, there can not be added a foreign key based on the <shortened tablename>_FS_ID field because there is no matching unique or primary key for it (since the <shortened table name>_FS_ID could appear many times depending of the versioning).

    On top of these issues, the filtering must support "release filtering" and "current state filtering".

    ...based on this your suggestion with DelegatingReverseEngineeringStrategy doesn't fit. Thanks anyway.

    So, basically from this point of view the hibernate tool does not support First Spirit standards/style (there are many aspects).

    In the end I had to do more customization to the hibernate-tool, including changed and new templates in order to support FS at DB level - for reverse engineering.

    Marius

    0
  • Zendesk API User
    Author: feddersen - 8/11/2010 9:42

    My understanding was that you don't want to modify the DDL at all and use it to generate model classes only. So you wouldn't need to create foreign keys in the database, which isn't easy because of the temporal aspect of all tables. I don't know if it's possible in Oracle, it might be if you're able to use assertions in foreign keys. That's the primary reason why we switched from foreign keys to a index based approach. Most databases don't support that kind of complex foreign key relationships. Have a look at

    So generating the correct mapping in your model classes should be possible if your reverse engineering uses defined indices to detect relationships between tables, or I'm missing something? Developing Time-Oriented Database Applications in SQL provides some insight on the rationale behind this approach. Chapter 2.1 and Chapter 5 describe the concept and the problems with primary/foreign keys.

    Implementing the temporal aspect for CRUD operations would be a second task. You basically need to overload all queries to include the time constraints (fs_valid_from, fs_valid_to). Release filtering would use fs_valid_from and fs_release_to.

    Marius Cimpean wrote:

    In the end I had to do more customization to the hibernate-tool, including changed and new templates in order to support FS at DB level - for reverse engineering.


    So do you have already have a working version? I'm curious to know which aspects of Hibernate need to be extended to get it working.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.