我尝试将我的实体保存到我的数据库中并面临the ORA-01861: literal does not match format string
错误。我知道大多数时候日期和字符串转换之间的错误会导致此消息。我也可能是这种情况,但我不知道为什么。这是 sql 语句(来自分析器):
INSERT INTO Person (no_person, first_name, usual_name, last_name,
birth_date, comments, c_user_creation, date_creation, c_user_modification,
date_modification, email, id_rh, cod_civ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ? ) Parameters: { 1: '173704', 2: Test, 3: 'null', 4: Test, 5: Object(DateTime), 6: 'null',
7: Web, 8: Object(DateTime), 9: 'null', 10: 'null', 11: zefzf@dgeghte.fr, 12: 'null', 13: '1'}
Time: 0.00 ms
个人实体:
<?php
namespace my\myBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* my\myBundle\Entity\Person
*
* @ORM\Table(name="Person")
* @ORM\Entity(repositoryClass="my\myBundle\Entity\PersonRepository")
*/
class Person
{
/**
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\Column(name="no_Person", type="integer")
* @ORM\SequenceGenerator(sequenceName="SEQ_NO_Person")
*/
public $noPerson;
/**
*
* @ORM\ManyToOne(targetEntity="civility")
* @ORM\JoinColumn(name="cod_civ", referencedColumnName="cod_civ")
*/
private $civility;
/**
* @var string $firstName
*
* @ORM\Column(name="first_name", type="string", length=30)
*/
private $firstName;
/**
* @var string $usualName
*
* @ORM\Column(name="usual_name", type="string", length=30)
*/
private $usualName;
/**
* @var string $lastName
*
* @ORM\Column(name="last_name", type="string", length=20)
*/
private $lastName;
/**
* @var date $birthDate
*
* @ORM\Column(name="birth_date", type="date")
*/
private $birthDate;
/**
* @var string $comment
*
* @ORM\Column(name="comment", type="string", length=300)
*/
private $comment;
/**
* @var string $cUserCreation
*
* @ORM\Column(name="c_user_creation", type="string", length=30)
*/
private $cUserCreation;
/**
* @var date $dCreation
*
* @ORM\Column(name="date_creation", type="date")
*/
private $dCreation;
/**
* @var string $cUserModification
*
* @ORM\Column(name="c_user_modification", type="string", length=30)
*/
private $cUserModification;
/**
* @var date $dModification
*
* @ORM\Column(name="date_modification", type="date")
*/
private $dModification;
/**
* @var string $email
*
* @ORM\Column(name="email", type="string", length=100)
*/
private $email;
/**
* @var integer $idRh
*
* @ORM\Column(name="id_rh", type="integer")
*/
private $idRh;
/**
* @var \Doctrine\Common\Collections\ArrayCollection $accCip
*
* @ORM\OneToMany(targetEntity="my\myBundle\Entity\AccCip",mappedBy="Person")
*/
private $accCip;
/**
* @var \Doctrine\Common\Collections\ArrayCollection $cartes
*
* @ORM\OneToMany(targetEntity="my\myBundle\Entity\Carte",mappedBy="Person")
*/
private $cartes;
/**
* @var \Doctrine\Common\Collections\ArrayCollection $panier
*
* @ORM\OneToMany(targetEntity="my\myBundle\Entity\Panier",mappedBy="Person")
*/
private $panier;
/**
* @var \Doctrine\Common\Collections\ArrayCollection $transactions
*
* @ORM\OneToMany(targetEntity="my\myBundle\Entity\TransactionPaybox",mappedBy="Person")
*/
private $transactions;
/**
* @var my\myBundle\Entity\Adresse $adresses
*
* @ORM\OneToMany(targetEntity="my\myBundle\Entity\Adresse",mappedBy="Person",cascade={"persist"})
*/
private $adresses;
public function __construct()
{
$this->cUserCreation = "Web";
$this->dCreation = new \DateTime();
$this->birthDate = new \DateTime();
$this->cartes = new \Doctrine\Common\Collections\ArrayCollection();
$this->accCip = new \Doctrine\Common\Collections\ArrayCollection();
$this->panier = new \Doctrine\Common\Collections\ArrayCollection();
$this->transactions = new \Doctrine\Common\Collections\ArrayCollection();
$this->insActSpos = new \Doctrine\Common\Collections\ArrayCollection();
$this->adresses = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get noPerson
*
* @return integer
*/
public function getNoPerson()
{
return $this->noPerson;
}
/**
* Set firstName
*
* @param string $firstName
*/
public function setfirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* Get firstName
*
* @return string
*/
public function getfirstName()
{
return $this->firstName;
}
/**
* Set usualName
*
* @param string $usualName
*/
public function setusualName($usualName)
{
$this->usualName = $usualName;
}
/**
* Get usualName
*
* @return string
*/
public function getusualName()
{
return $this->usualName;
}
/**
* Set lastName
*
* @param string $lastName
*/
public function setlastName($lastName)
{
$this->lastName = $lastName;
}
/**
* Get lastName
*
* @return string
*/
public function getlastName()
{
return $this->lastName;
}
/**
* Set birthDate
*
* @param string $birthDate
*/
public function setbirthDate(\DateTime $birthDate)
{
$this->birthDate = clone $birthDate;
}
/**
* Get birthDate
*
* @return string
*/
public function getbirthDate()
{
return $this->birthDate;
}
/**
* Set comment
*
* @param string $comment
*/
public function setcomment($comment)
{
$this->comment = $comment;
}
/**
* Get comment
*
* @return string
*/
public function getcomment()
{
return $this->comment;
}
/**
* Set cUserCreation
*
* @param string $cUserCreation
*/
public function setCUserCreation($cUserCreation)
{
$this->cUserCreation = $cUserCreation;
}
/**
* Get cUserCreation
*
* @return string
*/
public function getCUserCreation()
{
return $this->cUserCreation;
}
/**
* Set dCreation
*
* @param string $dCreation
*/
public function setDCreation(\DateTime $dCreation)
{
$this->dCreation = clone $dCreation;
}
/**
* Get dCreation
*
* @return string
*/
public function getDCreation()
{
return $this->dCreation;
}
/**
* Set cUserModification
*
* @param string $cUserModification
*/
public function setCUserModification($cUserModification)
{
$this->cUserModification = $cUserModification;
}
/**
* Get cUserModification
*
* @return string
*/
public function getCUserModification()
{
return $this->cUserModification;
}
/**
* Set dModification
*
* @param string $dModification
*/
public function setDModification(\DateTime $dModification)
{
$this->dModification = clone $dModification;
}
/**
* Get dModification
*
* @return string
*/
public function getDModification()
{
return $this->dModification;
}
/**
* Set email
*
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set idRh
*
* @param integer $idRh
*/
public function setIdRh($idRh)
{
$this->idRh = $idRh;
}
/**
* Get idRh
*
* @return integer
*/
public function getIdRh()
{
return $this->idRh;
}
/**
* Set civility
*
* @param my\myBundle\Entity\civility $civility
*/
public function setcivility(\my\myBundle\Entity\civility $civility)
{
$this->civility = $civility;
}
/**
* Get civility
*
* @return my\myBundle\Entity\civility
*/
public function getcivility()
{
return $this->civility;
}
/**
* Get accCip
*
* @return \Doctrine\Common\Collections\ArrayCollection;
*
*/
public function getAccCip(){
return $this->accCip;
}
/**
* Add accCip
*
* @param AccCip $accCip;
*
* @return Person
*
*/
public function addAccCip(AccCip $accCip)
{
$this->accCip[] = $accCip;
$accCip->setPerson($this);
return $this;
}
/**
* Remove accCip
*
* @param AccCip $accCip;
*
*
*/
public function removeAccCip(AccCip $accCip)
{
$this->accCip->removeElement($accCip);
}
/**
* Get cartes
*
* @return \Doctrine\Common\Collections\ArrayCollection
*
*/
public function getCartes(){
return $this->cartes;
}
/**
* Add carte
*
* @param Carte $carte;
*
* @return Person
*
*/
public function addCarte(Carte $carte)
{
$this->cartes[] = $carte;
$carte->setPerson($this);
return $this;
}
/**
* Remove carte
*
* @param Carte $carte;
*
*
*/
public function removeCarte(Carte $carte)
{
$this->cartes->removeElement($carte);
}
/**
* Has carte
*
* @return boolean
*
*/
public function hasCarte()
{
return $this->cartes->count()!=0;
}
/**
* Get panier
*
* @return \Doctrine\Common\Collections\ArrayCollection
*
*/
public function getPanier(){
return $this->panier;
}
/**
* Add panier
*
* @param Panier $panier;
*
* @return Person
*
*/
public function addPanier(Panier $panier)
{
$this->panier[] = $panier;
$panier->setPerson($this);
return $this;
}
/**
* Remove panier
*
* @param Panier $panier;
*
*
*/
public function removePanier(Panier $panier)
{
$this->panier->removeElement($panier);
}
/**
* Get Somme Panier
*
* @return float
*
*/
public function getSommePanier()
{
$somme=0;
foreach ($this->panier as $item){
$somme+=$item->getMontant();
}
return $somme;
}
/**
* Get transactions
*
* @return \Doctrine\Common\Collections\ArrayCollection
*
*/
public function getTransactions(){
return $this->transactions;
}
/**
* Add transaction
*
* @param TransactionPaybox $transaction;
*
* @return Person
*
*/
public function addTransaction(TransactionPaybox $transaction)
{
$this->transactions[] = $transaction;
$transaction->setPerson($this);
return $this;
}
/**
* Remove transaction
*
* @param TransactionPaybox $transaction;
*
*
*/
public function removeTransaction(TransactionPaybox $transaction)
{
$this->transactions->removeElement($transaction);
}
/**
* Get adresses
*
* @return \Doctrine\Common\Collections\ArrayCollection
*
*/
public function getAdresses(){
return $this->adresses;
}
/**
* Add Adresse
*
* @param my\myBundle\Entity\Adresse $adresse;
*
* @return Person
*
*/
public function addAdresse(Adresse $adresse)
{
$this->adresses[] = $adresse;
$adresse->setPerson($this);
return $this;
}
/**
* Remove adresses
*
* @param my\myBundle\Entity\Adresse $adresse;
*
*
*/
public function removeAdresse(Adresse $adresse)
{
$this->adresses->removeElement($adresse);
}
}
SQL:
CREATE TABLE "MYDB"."PERSON"
( "NO_PERSON" NUMBER(8,0),
"COD_CIV" VARCHAR2(1 BYTE),
"FIRST_NAME" VARCHAR2(30 BYTE),
"USUAL_NAME" VARCHAR2(30 BYTE),
"LAST_NAME" VARCHAR2(20 BYTE),
"BIRTH_DATE" DATE,
"COMMENT" VARCHAR2(300 BYTE),
"C_USER_CREATION" VARCHAR2(30 BYTE),
"DATE_CREATION" DATE,
"C_USER_MODIFICATION" VARCHAR2(30 BYTE),
"DATE_MODIFICATION" DATE,
"EMAIL" VARCHAR2(100 BYTE),
"ID_RH" NUMBER(8,0),
)
编辑:更多信息。我最近将日期更改为实际类型日期(因为它们在以前的版本中是“字符串”(此时我不是开发人员)。当学说尝试创建实体时,它会抛出此异常:
Could not convert database value "08/07/92" to Doctrine Type date. Expected format: Y-m-d 00:00:00
数据库中的日期实际上是“日期”sql 的类型。