got a symfony project, updating from 5.1 to 6.4 LTS and doctrine to 3.0.0.
Got this Entity updating from annotations to PHP8 attributes:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: "App\Repository\SottocontiUtentiRepository")]
class SottocontiUtenti
{
#[ORM\Id]
#[Column(type: "integer")]
private int $utente_id;
#[ORM\Id]
#[Column(type: "integer")]
private int $pratica_id;
#[ORM\Id]
#[Column(type: "integer")]
private int $finanziamento_id;
#[Column(type: "string")]
private $nome;
#[Column(type: "string")]
private $cognome;
// Ripristino della relazione
#[ORM\ORM\Id()]
#[ManyToOne(targetEntity: Sottoconti::class, inversedBy: "utenti")]
#[JoinColumn(name: "sottoconto_id", referencedColumnName: "sottoconto_id", nullable: true)]
private ?Sottoconti $sottoconto_id; // Nota l'utilizzo del tipo per Sottoconti
#[Column(type: "float", nullable: true)]
private $importo_deliberato;
#[Column(type: "string", nullable: true)]
private $rientro;
public function getUtenteId(): ?int
{
return $this->utente_id;
}
public function setUtenteId(int $utente_id): self
{
$this->utente_id = $utente_id;
return $this;
}
public function getSottocontoId(): ?Sottoconti
{
return $this->sottoconto_id;
}
public function setSottocontoId(?Sottoconti $sottoconto_id): self
{
$this->sottoconto_id = $sottoconto_id;
return $this;
}
public function getPraticaId(): ?int
{
return $this->pratica_id;
}
public function setPraticaId(int $pratica_id): self
{
$this->pratica_id = $pratica_id;
return $this;
}
public function getFinanziamentoId(): ?int
{
return $this->finanziamento_id;
}
public function setFinanziamentoId(int $finanziamento_id): self
{
$this->finanziamento_id = $finanziamento_id;
return $this;
}
public function getImportoDeliberato(): ?float
{
return $this->importo_deliberato;
}
public function setImportoDeliberato(?float $importo_deliberato): self
{
$this->importo_deliberato = $importo_deliberato;
return $this;
}
/**
* @return mixed
*/
public function getRientro()
{
return $this->rientro;
}
/**
* @param mixed $rientro
*/
public function setRientro($rientro): void
{
$this->rientro = $rientro;
}
}
Getting this error: No identifier/primary key specified for Entity "App\Entity\SottocontiUtenti". Every Entity must have an identifier/primary key.
Tried to Google it and ask to Gemini ADV or ChatGPT. Nothing works. Also tried this way: https://www.doctrine-project.org/projects/doctrine-orm/en/3.0/tutorials/composite-primary-keys.html#composite-and-foreign-keys-as-primary-key
But still got the same error.
Any suggestion?
Thanks a lot, Giacomo.
It looks like you are missing the actual primary id field of the
importo_deliberatotable, plus you should only use#[ORM\Id]at the primary id field and not at other foreign ids... here is an sample taken from the symfony demo app: