Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:48:13+00:00 2026-06-08T17:48:13+00:00

In our database we have tables which have no single auto-increment primary key but

  • 0

In our database we have tables which have no single auto-increment primary key but instead a composite one, which may or may not include an auto-increment field as the first field for that primary key.

For example:

DROP TABLE IF EXISTS `gen_5_23`;
CREATE TABLE IF NOT EXISTS `gen_5_23` (
    `id_azienda` int(10) unsigned NULL DEFAULT 1,
    `id_sede` int(10) unsigned NULL DEFAULT 1,
    `revisione_documento` int(10) unsigned NULL DEFAULT 0,
    `premessa_generale` text,
    `flag_stampa` char(1) DEFAULT 'N',
    PRIMARY KEY (`id_azienda`,`id_sede`,`revisione_documento`),
    CONSTRAINT `fk_revisione_documento_gen_5_23` FOREIGN KEY (`revisione_documento`, `id_azienda`, `id_sede`) REFERENCES `agews_revisioni_documenti` (`revisione_documento`, `id_azienda`, `id_sede`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `gen_5_23_consumi`;
CREATE TABLE IF NOT EXISTS `gen_5_23_consumi` (
    `id_consumo` int(10) unsigned AUTO_INCREMENT,
    `id_azienda` int(10) unsigned NULL DEFAULT 1,
    `id_sede` int(10) unsigned NULL DEFAULT 1,
    `revisione_documento` int(10) unsigned NULL DEFAULT 0,
    `consumo` varchar(255) NULL DEFAULT NULL,
    `unita` varchar(255) NULL DEFAULT NULL,
    `valore` float(11,2) NULL DEFAULT 0,
    PRIMARY KEY (id_consumo,`id_azienda`,`id_sede`,`revisione_documento`),
    CONSTRAINT `fk_main_gen_5_23_consumi` FOREIGN KEY (`id_azienda`, `id_sede`, `revisione_documento`) REFERENCES `gen_5_23` (`id_azienda`, `id_sede`, `revisione_documento`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The key in gen_5_23_consumi is defined as is ’cause there are procedures in our webapp which would blindly take a row, change only id_azienda or id_sede or revisione_documento and then re-insert it, in this way the row would be valid, as it would not be if the primary key was only id_consumo.

We’re considering to start using doctrine 2 for database management, but I do not understand from the docs how would you implement such an entity, if it is ever possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:48:14+00:00Added an answer on June 8, 2026 at 5:48 pm

    It is possible but not out of the box. You can have composite key as primary keys for your entities: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html but auto increment implementation should be done in your code because of

    Every entity with a composite key cannot use an id generator other
    than “ASSIGNED”. That means the ID fields have to have their values
    set before you call EntityManager#persist($entity).

    To emulate auto increment behavior you can have sequence table with id as the auto increment PK and create an entity for this table. Add relation from your main entity to entity that represents auto increment sequence, see class ArticleAttribute from the page above, your code should be very similar:

    Class Gen523consumiAuto
    {
        /** @Id @Column(type="integer") @GeneratedValue */
        private $id;
    }
    
    Class Gen523consumi
    {
        /** @Id @OneToOne(targetEntity="Gen523consumiAuto") */
        private $idConsumo;
    
        /** @Id @Column(type="integer") */
        private $idAzienda;
    
        /** @Id @Column(type="integer") */
        private $idSede;
    
        /** @Id @Column(type="integer") */
        private $revisioneDocumento;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our team we have a database project in visual Studio 2008 which is
Our client's database admins have requested that we don't use temp tables within our
We've encountered the following situation in our database. We have table 'A' and table
I have 100000 Ids to store into our DataBase. Id is in string format.each
We have an Informix 4GL forms interface to our database, accessed using a terminal
We have been storing our staging database on the production database server with the
We have recently improved the schema of our production database, changing column names and
I have a tool that is setup to query our Clearquest Database to return
I have a data mart mastered from our OLTP Oracle database using basic Materialized
Our scenario: We have a main database that stores company-wide information. We have several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.