DDC-658: Reverse engineering with Oracle (DBDriver and Associations as Identifier) #810

Open
opened 2026-01-22 12:51:14 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 27, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user mikaelkael:

I am playing with reverse engineering with Oracle and I have some problems:

My schema:

drop table PHONE_NUMBER;
drop table CUSTOMER;

create table CUSTOMER (
   CUSTOMER_ID             NUMBER(4)                       not null,
   CUSTOMER_LASTNAME       VARCHAR2(50)                    not null,
   CUSTOMER_MODIFIED       DATE,
   constraint PK*CUSTOMER primary key (CUSTOMER*ID)
         using index
       tablespace TBS_INDEX
       storage
       (
           initial 100K
           next 100K
       )
)
storage
(
    initial 100K
    next 100K
)
tablespace TBS_DATA;

create table PHONE_NUMBER (
   PHONE*NUMBER*ID         NUMBER(4)                       not null,
   CUSTOMER_ID             NUMBER(4)                       not null,
   PHONE_NUMBER            VARCHAR2(50)                    not null,
   PHONE_NUMBERMODIFIED    DATE,
   constraint PK*PHONE_NUMBER primary key (PHONE_NUMBER_ID, CUSTOMER*ID)
         using index
       tablespace TBS_INDEX
       storage
       (
           initial 100K
           next 100K
       )
)
storage
(
    initial 100K
    next 100K
)
tablespace TBS_DATA;

alter table PHONE_NUMBER
   add constraint PHONE*NUMBER__CUSTOMER foreign key (CUSTOMER*ID)
      references CUSTOMER (CUSTOMER_ID);

I obtain "Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Property "customerId" in "PhoneNumber" was already declared, but it must be declared only once'"

It's because a foreign key is a component of the primary key.

Originally created by @doctrinebot on GitHub (Jun 27, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user mikaelkael: I am playing with reverse engineering with Oracle and I have some problems: My schema: ``` drop table PHONE_NUMBER; drop table CUSTOMER; create table CUSTOMER ( CUSTOMER_ID NUMBER(4) not null, CUSTOMER_LASTNAME VARCHAR2(50) not null, CUSTOMER_MODIFIED DATE, constraint PK*CUSTOMER primary key (CUSTOMER*ID) using index tablespace TBS_INDEX storage ( initial 100K next 100K ) ) storage ( initial 100K next 100K ) tablespace TBS_DATA; create table PHONE_NUMBER ( PHONE*NUMBER*ID NUMBER(4) not null, CUSTOMER_ID NUMBER(4) not null, PHONE_NUMBER VARCHAR2(50) not null, PHONE_NUMBERMODIFIED DATE, constraint PK*PHONE_NUMBER primary key (PHONE_NUMBER_ID, CUSTOMER*ID) using index tablespace TBS_INDEX storage ( initial 100K next 100K ) ) storage ( initial 100K next 100K ) tablespace TBS_DATA; alter table PHONE_NUMBER add constraint PHONE*NUMBER__CUSTOMER foreign key (CUSTOMER*ID) references CUSTOMER (CUSTOMER_ID); ``` I obtain "Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Property "customerId" in "PhoneNumber" was already declared, but it must be declared only once'" It's because a foreign key is a component of the primary key.
Author
Owner

@doctrinebot commented on GitHub (Jun 28, 2010):

Comment created by mikaelkael:

This is the continuation of http://www.doctrine-project.org/jira/browse/DDC-616. Only the schema is different.

@doctrinebot commented on GitHub (Jun 28, 2010): Comment created by mikaelkael: This is the continuation of http://www.doctrine-project.org/jira/browse/[DDC-616](http://www.doctrine-project.org/jira/browse/DDC-616). Only the schema is different.
Author
Owner

@doctrinebot commented on GitHub (Jun 28, 2010):

Comment created by @beberlei:

just for understanding this scenario:

Is this a One-To-One relation and the TABLE_TEST2 "inherits" the primary key from its parent TABLE_TEST1?

If yes, this construct is not yet supported by Doctrine 2, we still need to include an ID-Generator that supports this kind of schema.

@doctrinebot commented on GitHub (Jun 28, 2010): Comment created by @beberlei: just for understanding this scenario: Is this a One-To-One relation and the TABLE_TEST2 "inherits" the primary key from its parent TABLE_TEST1? If yes, this construct is not yet supported by Doctrine 2, we still need to include an ID-Generator that supports this kind of schema.
Author
Owner

@doctrinebot commented on GitHub (Jun 28, 2010):

Comment created by mikaelkael:

Change for a more understandable use case. Note that it's not my real use case and that I work on legacy database on which I can't change the structure.

@doctrinebot commented on GitHub (Jun 28, 2010): Comment created by mikaelkael: Change for a more understandable use case. Note that it's not my real use case and that I work on legacy database on which I can't change the structure.
Author
Owner

@doctrinebot commented on GitHub (Jan 1, 2011):

Comment created by @beberlei:

updated the issue topic to get a better grasp of what needs to be done here.

@doctrinebot commented on GitHub (Jan 1, 2011): Comment created by @beberlei: updated the issue topic to get a better grasp of what needs to be done here.
Author
Owner

@doctrinebot commented on GitHub (Jun 9, 2011):

Comment created by waldo2188:

I have the same error with Mysql whit the same condition.

@doctrinebot commented on GitHub (Jun 9, 2011): Comment created by waldo2188: I have the same error with Mysql whit the same condition.
Author
Owner

@doctrinebot commented on GitHub (Nov 28, 2011):

Comment created by @beberlei:

More details on the work to be done:

The relevant code is in Doctrine/ORM/Mapping/Driver/DatabaseDriver.php only.

The idea is currently many-to-many tables are detected by checking that the table has foreign keys on all the primary key columns (no additional columns!)

Now with the 2.1 feature of foreign key/primary key entities this is not necessarily true anymore. You can have the primary keys being foreign keys BUT have additional columns that are not part of the primary key. This has to be detected.

If a foreign key-primary-key entity is found that has additional columns a ClassMetadata has to be created and the associations have to be created with the "id" => true flag in mapManyToOne().

@doctrinebot commented on GitHub (Nov 28, 2011): Comment created by @beberlei: More details on the work to be done: The relevant code is in Doctrine/ORM/Mapping/Driver/DatabaseDriver.php only. The idea is currently many-to-many tables are detected by checking that the table has foreign keys on all the primary key columns (no additional columns!) Now with the 2.1 feature of foreign key/primary key entities this is not necessarily true anymore. You can have the primary keys being foreign keys BUT have additional columns that are not part of the primary key. This has to be detected. If a foreign key-primary-key entity is found that has additional columns a ClassMetadata has to be created and the associations have to be created with the "id" => true flag in mapManyToOne().
Author
Owner

@doctrinebot commented on GitHub (Dec 11, 2011):

Comment created by scott459:

For what it's worth, I'm getting this error when I have a PK that is a single column and not a FK.

PRIMARY KEY (id),
UNIQUE KEY cycle*station_id (cycle,station*id),
KEY station*id_idx (station*id),
KEY readings (readings),
KEY source (source),
KEY temperature*min_max (temperature_max,temperature*min),
KEY station*id_cycle (station_id,cycle,updated*at),
CONSTRAINT compiled*1_station_id_stations_id FOREIGN KEY (station*id) REFERENCES stations (id),
CONSTRAINT compiled*1_station_id_stations_id_1 FOREIGN KEY (station*id) REFERENCES stations (id) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=160833690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

@doctrinebot commented on GitHub (Dec 11, 2011): Comment created by scott459: For what it's worth, I'm getting this error when I have a PK that is a single column and not a FK. PRIMARY KEY (`id`), UNIQUE KEY `cycle*station_id` (`cycle`,`station*id`), KEY `station*id_idx` (`station*id`), KEY `readings` (`readings`), KEY `source` (`source`), KEY `temperature*min_max` (`temperature_max`,`temperature*min`), KEY `station*id_cycle` (`station_id`,`cycle`,`updated*at`), CONSTRAINT `compiled*1_station_id_stations_id` FOREIGN KEY (`station*id`) REFERENCES `stations` (`id`), CONSTRAINT `compiled*1_station_id_stations_id_1` FOREIGN KEY (`station*id`) REFERENCES `stations` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=160833690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#810