php - Error with id on INSERT INTO entity on Doctrine2/Symfony2 -
since days, i've problème 1 of entity. entity has id defined manually (no auto-increment). when try define it, doctrine return error on insert query :
dbalexception: exception occurred while executing 'insert infosperso (num, login, nom, prenom, email, societe, adr1, adr2, cp, ville, tel, fax, nichandle, parrain, actif, state, emailvalide, date_creation, id_entite_legale_pays, pays) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' params [null, "test", "hebert", "donovan", "test@mail.com", "sncf", "tempore excepteur nulla molestiae sed temporibus eum officia error illo tempore et amet voluptatum vel modi cupiditate", "laboriosam eiusmod dolor non saepe incidunt cillum corrupti occaecat dolorem tempore aut quis esse autem", "13001", "marseille", "0442910000", "0442499569", 0, null, 1, 0, 1, "2015-06-04 11:09:46.000", null, 171]:
sqlstate[hy000]: general error: 515 general sql server error: check messages sql server [515] (severity 16) [(null)]
here current code :
$infosperso = new infosperso(); $infosperso->setlogin($client->getlogin()) ->setparrain($leaderbmcid) ->setnichandle(0) ->setnom($client->getname()) ->setprenom($client->getfirstname()) ->setemail($client->getemail()) ->setadr1($client->getaddress()) ->setadr2($client->getcomplementaryaddress()) ->setcp($client->getzipcode()) ->setdatecreation($client->getcreationdate()) ->settel($client->getphone()) ->setfax($client->getfax()) ->setville($client->getcity()) ->setpays($client->getcountry())// entity pays ->setsociete($client->getcompany()->getlibcompanies()) ->setemailvalide(true) ->setstate(0) ->setactif(1);
and entity definition id :
/** * @var integer $num * * @orm\column(name="num", type="integer") * @orm\id * @orm\generatedvalue(strategy="custom") * @orm\customidgenerator(class="bizdatasbundle\database\bmc\infospersoidgenerator") */ private $num;
the infospersoidgenerator class defined that:
<?php namespace bizdatasbundle\database\bmc; use doctrine\orm\id\abstractidgenerator; class infospersoidgenerator extends abstractidgenerator { public function generate(\doctrine\orm\entitymanager $em, $entity) { $maxid = $em->createquerybuilder('ip') ->select('max(ip.num)') ->from('bizdatasbundle:bmc\\infosperso', 'ip') ->getquery() ->getsinglescalarresult(); $maxid++; return $maxid; } }
if echo on $maxid
, print correct id set. when doctrine flushes, id set null
in query , didn't find why.
if you've idea. !
okay, let's see:
you dumping $maxid
returns correct value, if closely @ code provided, not setting value infosperso
. more you're missing ->setnum( $maxid )
.
and way, can see in sql query:
insert infosperso (num...) // , rest of columns here
and right after that:
with params [null,...]
as can see, did not provide value column.
and last note, if you're gonna generate id's yourself, can remove generatedvalue
annotation. quote documentation:
none: tells doctrine identifiers assigned (and generated) code. assignment must take place before new entity passed entitymanager#persist. none same leaving off @generatedvalue entirely.
Comments
Post a Comment