Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 10.04 + Oracle 11g Entreprise + PHP 5.3.2 + Doctrine2 Git (up-to-date)

      Description

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

      My schema:

      create table TABLE_TEST1 (
         TEST1_FIRST_COLUMN      NUMBER(4)                       not null,
         TEST1_SECOND_COLUMN     VARCHAR2(50)                    not null,
         TEST1_THIRD_COLUMN      DATE,
         constraint PK_TABLE_TEST1 primary key (TEST1_FIRST_COLUMN)
               using index
             tablespace TBS_INDEX
             storage
             (
                 initial 100K
                 next 100K
             )
      )
      storage
      (
          initial 100K
          next 100K
      )
      tablespace TBS_DATA;
      
      create table TABLE_TEST2 (
         TEST2_FIRST_COLUMN      NUMBER(4)                       not null,
         TEST2_SECOND_COLUMN     VARCHAR2(50)                    not null,
         TEST2_THIRD_COLUMN      DATE,
         TEST1_FIRST_COLUMN      NUMBER(4)                       not null,
         constraint PK_TABLE_TEST2 primary key (TEST2_FIRST_COLUMN)
               using index
             tablespace TBS_INDEX
             storage
             (
                 initial 100K
                 next 100K
             )
      )
      storage
      (
          initial 100K
          next 100K
      )
      tablespace TBS_DATA;
      
      alter table TABLE_TEST2
         add constraint TABLE_TEST2__TABLE_TEST1 foreign key (TEST1_FIRST_COLUMN)
            references TABLE_TEST1 (TEST1_FIRST_COLUMN);
      

      My reverse engineering code:

      ini_set('display_errors', 1);
      set_include_path(realpath(__DIR__ . '/../doctrine-orm/lib/'));
      
      require 'Doctrine/Common/ClassLoader.php';
      $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', realpath(__DIR__ . '/../doctrine-orm/lib/'));
      $classLoader->register();
      
      $config = new \Doctrine\ORM\Configuration;
      $cache = new \Doctrine\Common\Cache\ApcCache;
      $config->setMetadataCacheImpl($cache);
      $driverImpl = $config->newDefaultAnnotationDriver(realpath(__DIR__. '/Infofab/Entities'));
      $config->setMetadataDriverImpl($driverImpl);
      $config->setQueryCacheImpl($cache);
      $config->setProxyDir('Proxies');
      $config->setProxyNamespace('Infofab');
      $connectionOptions = array(
          'dbname' => 'bddmkk',
          'user' => 'doctrine',
          'password' => 'xxxxxxx',
          'host' => 'localhost',
          'driver' => 'pdo_oci',
          'driverOptions' => array(PDO::ATTR_CASE => PDO::CASE_LOWER)
      );
      
      $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
      
      $sm = $em->getConnection()->getSchemaManager();
      
      $em->getConfiguration()->setMetadataDriverImpl(
          new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
              $em->getConnection()->getSchemaManager()
          )
      );
      
      $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($em);
      $metadata = $cmf->getAllMetadata();
      
      $cme = new \Doctrine\ORM\Tools\Export\ClassMetadataExporter();
      $exporter = $cme->getExporter('annotation', 'Infofab');
      $exporter->setMetadata($metadata);
      $etg = new \Doctrine\ORM\Tools\EntityGenerator;
      $exporter->setEntityGenerator($etg);
      $exporter->export();
      

      If I run this code, I obtain 2 entities:

      <?php
      /**
       * TableTest1
       *
       * @Table(name="TABLE_TEST1")
       * @Entity
       */
      class TableTest1
      {
          /**
           * @var integer $test1FirstColumn
           *
           * @Column(name="TEST1_FIRST_COLUMN", type="integer", nullable=false)
           * @Id
           * @GeneratedValue(strategy="SEQUENCE")
           * @SequenceGenerator(sequenceName="TABLE_TEST1_TEST1_FIRST_COLUMN", allocationSize="10", initialValue="1")
           */
          private $test1FirstColumn;
      
          /**
           * @var string $test1SecondColumn
           *
           * @Column(name="TEST1_SECOND_COLUMN", type="string", length=50, nullable=false)
           */
          private $test1SecondColumn;
      
          /**
           * @var datetime $test1ThirdColumn
           *
           * @Column(name="TEST1_THIRD_COLUMN", type="datetime", nullable=true)
           */
          private $test1ThirdColumn;
      }
      

      and

      <?php
      /**
       * TableTest2
       *
       * @Table(name="TABLE_TEST2")
       * @Entity
       */
      class TableTest2
      {
          /**
           * @var integer $test2FirstColumn
           *
           * @Column(name="TEST2_FIRST_COLUMN", type="integer", nullable=false)
           * @Id
           * @GeneratedValue(strategy="SEQUENCE")
           * @SequenceGenerator(sequenceName="TABLE_TEST2_TEST2_FIRST_COLUMN", allocationSize="10", initialValue="1")
           */
          private $test2FirstColumn;
      
          /**
           * @var integer $test1FirstColumn
           *
           * @Column(name="TEST1_FIRST_COLUMN", type="integer", nullable=false)
           */
          private $test1FirstColumn;
      
          /**
           * @var string $test2SecondColumn
           *
           * @Column(name="TEST2_SECOND_COLUMN", type="string", length=50, nullable=false)
           */
          private $test2SecondColumn;
      
          /**
           * @var datetime $test2ThirdColumn
           *
           * @Column(name="TEST2_THIRD_COLUMN", type="datetime", nullable=true)
           */
          private $test2ThirdColumn;
      
          /**
           * @var TABLETEST1
           *
           * @OneToOne(targetEntity="TABLETEST1")
           * @JoinColumns({
           *   @JoinColumn(name="TEST1_FIRST_COLUMN", referencedColumnName="TEST1_FIRST_COLUMN")
           * })
           */
          private $tEST1FIRSTCOLUMN;
      }
      

      As you can see, it declares 2 times the same column: private $test1FirstColumn; and private $tEST1FIRSTCOLUMN;

        Issue Links

          Activity

          Hide
          Benjamin Eberlei added a comment -

          Fixed and scheduled for BETA 3

          Show
          Benjamin Eberlei added a comment - Fixed and scheduled for BETA 3
          Hide
          Mickael Perraud added a comment -

          Something is broken with your commit:

          Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'No identifier/primary key specified for Entity 'OUTILLAGE_OPERATION_COLLECTE'. Every Entity must have an identifier/primary key.' in /mkk01/doctrine/doctrine-orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 37
          
          Doctrine\ORM\Mapping\MappingException: No identifier/primary key specified for Entity 'OUTILLAGE_OPERATION_COLLECTE'. Every Entity must have an identifier/primary key. in /mkk01/doctrine/doctrine-orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 37
          

          In file 'lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php ' (http://github.com/doctrine/doctrine2/commit/b7db8df7efed4517859be562fd58e6ce4cc6354a) around line 86, the iteration is not complete and it is not able to define the primary key

          Show
          Mickael Perraud added a comment - Something is broken with your commit: Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'No identifier/primary key specified for Entity 'OUTILLAGE_OPERATION_COLLECTE'. Every Entity must have an identifier/primary key.' in /mkk01/doctrine/doctrine-orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 37 Doctrine\ORM\Mapping\MappingException: No identifier/primary key specified for Entity 'OUTILLAGE_OPERATION_COLLECTE'. Every Entity must have an identifier/primary key. in /mkk01/doctrine/doctrine-orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 37 In file 'lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php ' ( http://github.com/doctrine/doctrine2/commit/b7db8df7efed4517859be562fd58e6ce4cc6354a ) around line 86, the iteration is not complete and it is not able to define the primary key
          Hide
          Benjamin Eberlei added a comment -

          It seems the detection of many to many tables can cause severe problems. Some internal refactoring has to be done to get this reverse-engineering right.

          Show
          Benjamin Eberlei added a comment - It seems the detection of many to many tables can cause severe problems. Some internal refactoring has to be done to get this reverse-engineering right.
          Hide
          Benjamin Eberlei added a comment -

          This should now be finally solved. Many-To-Many tables are detected and supported in reverse engineering now.

          Show
          Benjamin Eberlei added a comment - This should now be finally solved. Many-To-Many tables are detected and supported in reverse engineering now.

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Mickael Perraud
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: