1
votes

I am reverse engineering our legacy Oracle Database using Hibernate and there are many database views that have columns that represent primary keys for the tables used in them. It turns out that all the views I'm working with have a primary key column or compound primary key (2 columns) that can uniquely identify each row in the view. We have defined update, insert, and delete operations for the views, too, so that the underlying tables are updated properly.

Hibernate cannot determine keys of views (since views don't naturally have a key) so it's a natural fit to give hibernate the keys so that it can reverse map the database, but I do not know how to specify the compound keys.

Is there a way to specify a compound key in the hibernate reverse engineering config xml?

1

1 Answers

2
votes

Simply add the second part of the key to the primary-key tag in the hibernate reverse engineering config file like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering 
  SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
    <schema-selection match-schema="MY_SCHEMA" match-table="MOE_VIEW"/>
    <table schema="MY_SCHEMA" name="MOE_VIEW">
        <primary-key>
            <key-column name="MR_MOE_ID"/>
            <key-column name="EXPERIMENT_ID"/>
        </primary-key>
    </table>
</hibernate-reverse-engineering>