Bonjour,

Ne trouvant pas de réponses à mon souci après de nombreuses recherches infructueuses, je poste cela ici dans l'espoir que quelqu'un puisse m'éclairer.

J'ai une entité Entreprise contenant une propriété SIREN et NIC, ces deux propriétés formant un code SIRET unique.
J'ai donc défini une contrainte Unique au début de mon entité ainsi qu'un UniqueEntity afin d'avoir un message de retour dans un formulaire dès la tentative d'un ajout avec code SIRET déjà en base.

Cependant, je n'obtiens pas ce message et j'obtiens juste un message d'erreur Symfony de type :
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '339057986-00012' for key 'SIRET'

Voici mon entité, tout me semble pourtant correct non? A moins que j'en fasse une mauvaise utilisation...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
 
namespace Proetco\FrontBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
 
/**
 * Proetco\FrontBundle\Entity\Entreprise
 *
 * @ORM\Table(name="entreprise", uniqueConstraints={@ORM\UniqueConstraint(name="SIRET", columns={"SIREN", "NIC"})}) 
 * @ORM\Entity(repositoryClass="Proetco\FrontBundle\Entity\EntrepriseRepository")
 * @UniqueEntity(fields={"SIREN","NIC"}, message="Cette entreprise est déjà enregistrée")
 */
class Entreprise
{
    protected $Siret;
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var string $SIREN
     *
     * @ORM\Column(name="SIREN", type="string", length=9)
     */
    private $SIREN;
 
    /**
     * @var string $NIC
     *
     * @ORM\Column(name="NIC", type="string", length=5)
     */
    private $NIC;
 
    /**
     * @var string $RS
     *
     * @ORM\Column(name="RS", type="string", length=45, nullable=true)
     */
    private $RS;
 
    /**
     * @var string $NCOM
     *
     * @ORM\Column(name="NCOM", type="string", length=45, nullable=true)
     */
    private $NCOM;
 
    /**
     * @var string $CPOS
     *
     * @ORM\Column(name="CPOS", type="string", length=5, nullable=true)
     */
    private $CPOS;
 
    /**
     * @var string $LCOM
     *
     * @ORM\Column(name="LCOM", type="string", length=45, nullable=true)
     */
    private $LCOM;
 
    /**
     * @var string $INSEE
     *
     * @ORM\Column(name="INSEE", type="string", length=5, nullable=true, nullable=true)
     */
    private $INSEE;
 
    /**
     * @var string $DEP
     *
     * @ORM\Column(name="DEP", type="string", length=2)
     */
    private $DEP;
 
    /**
     * @var string $ARR
     *
     * @ORM\Column(name="ARR", type="string", length=1, nullable=true)
     */
    private $ARR;
 
    /**
     * @var string $CAN
     *
     * @ORM\Column(name="CAN", type="string", length=2, nullable=true)
     */
    private $CAN;
 
 
    public function getSiret()
    {
        return $this->Siret;
    }
    public function setSiret($Siret)
    {
        $this->Siret = $Siret;
    }
 
 
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set SIREN
     *
     * @param string $sIREN
     */
    public function setSIREN($sIREN)
    {
        $this->SIREN = $sIREN;
    }
 
    /**
     * Get SIREN
     *
     * @return string 
     */
    public function getSIREN()
    {
        return $this->SIREN;
    }
 
    /**
     * Set NIC
     *
     * @param string $nIC
     */
    public function setNIC($nIC)
    {
        $this->NIC = $nIC;
    }
 
    /**
     * Get NIC
     *
     * @return string 
     */
    public function getNIC()
    {
        return $this->NIC;
    }
 
    /**
     * Set RS
     *
     * @param string $rS
     */
    public function setRS($rS)
    {
        $this->RS = $rS;
    }
 
    /**
     * Get RS
     *
     * @return string 
     */
    public function getRS()
    {
        return $this->RS;
    }
 
    /**
     * Set NCOM
     *
     * @param string $nCOM
     */
    public function setNCOM($nCOM)
    {
        $this->NCOM = $nCOM;
    }
 
    /**
     * Get NCOM
     *
     * @return string 
     */
    public function getNCOM()
    {
        return $this->NCOM;
    }
 
    /**
     * Set CPOS
     *
     * @param string $cPOS
     */
    public function setCPOS($cPOS)
    {
        $this->CPOS = $cPOS;
    }
 
    /**
     * Get CPOS
     *
     * @return string 
     */
    public function getCPOS()
    {
        return $this->CPOS;
    }
 
    /**
     * Set LCOM
     *
     * @param string $lCOM
     */
    public function setLCOM($lCOM)
    {
        $this->LCOM = $lCOM;
    }
 
    /**
     * Get LCOM
     *
     * @return string 
     */
    public function getLCOM()
    {
        return $this->LCOM;
    }
 
    /**
     * Set INSEE
     *
     * @param string $iNSEE
     */
    public function setINSEE($iNSEE)
    {
        $this->INSEE = $iNSEE;
    }
 
    /**
     * Get INSEE
     *
     * @return string 
     */
    public function getINSEE()
    {
        return $this->INSEE;
    }
 
    /**
     * Set DEP
     *
     * @param string $dEP
     */
    public function setDEP($dEP)
    {
        if (!isset($this->DEP))$this->DEP = '02';
        $this->DEP = $dEP;
    }
 
    /**
     * Get DEP
     *
     * @return string 
     */
    public function getDEP()
    {
        if (!isset($this->DEP))$this->DEP = '02';
        return $this->DEP;
    }
 
    /**
     * Set ARR
     *
     * @param string $aRR
     */
    public function setARR($aRR)
    {
        $this->ARR = $aRR;
    }
 
    /**
     * Get ARR
     *
     * @return string 
     */
    public function getARR()
    {
        return $this->ARR;
    }
 
    /**
     * Set CAN
     *
     * @param string $cAN
     */
    public function setCAN($cAN)
    {
        $this->CAN = $cAN;
    }
 
    /**
     * Get CAN
     *
     * @return string 
     */
    public function getCAN()
    {
        return $this->CAN;
    }
 
    public function retrieveSiren($siret){
        return substr($siret,0,9);
    }
 
    public function retrieveNic($siret){
        return substr($siret,-5,5);
    }
 
    //contraintes de validation
    //TODO : valider les champs avec Regex
 
    public function isSIREN(){
 
    }
 
    public function isNIC(){
 
    }
 
 
}
Merci d'avance pour votre aide.