This file is indexed.

/usr/share/doc/php-doctrine-orm/html/reference/annotations-reference.html is in doctrine-orm-doc 2.4.6-1+deb8u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>22. Annotations Reference &mdash; Doctrine 2 ORM 2 documentation</title>
    <link rel="stylesheet" href="../_static/bootstrap/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/layout.css" type="text/css" />
    <link rel="stylesheet" href="../_static/configurationblock.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/configurationblock.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/configurationblock.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/configurationblock.js"></script>
    <script src="../_static/bootstrap/js/bootstrap.min.js"></script>

    <script type="text/javascript">
    <!--
        $(document).ready(function() {
            $("#versions").change(function() {
                var docsUrl = $(this).val();
                window.location.href = docsUrl;
            });
        });
    -->
    </script>
    <link rel="shortcut icon" href="../_static/doctrine.ico"/>
    <link rel="top" title="Doctrine 2 ORM 2 documentation" href="../index.html" />
    <link rel="next" title="23. PHP Mapping" href="php-mapping.html" />
    <link rel="prev" title="21. YAML Mapping" href="yaml-mapping.html" /> 
  </head>
  <body>
    <div id="wrapper">
      <div id="header">
        <h1 id="h1title"></h1>
        <div id="logo">
          <a href="http://www.doctrine-project.org/">Doctrine - PHP Database Libraries</a>
        </div>
      </div>
      <div id="nav" class="cls">
        <div class="tl cls">
          <ul>
            <li><a target="_top" href="/">home</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/about">about</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/projects.html">projects</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/projects/orm">orm</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/projects/dbal">dbal</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/blog">blog</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/jira">development</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/contribute">contribute</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/community">community</a></li>
          </ul>
        </div>
      </div>
      <div id="content" class="cls">
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="php-mapping.html" title="23. PHP Mapping"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="yaml-mapping.html" title="21. YAML Mapping"
             accesskey="P">previous</a> |</li>
        <li><a href="/">Doctrine Homepage</a> &raquo;</li>
        <li><a href="../index.html">Doctrine 2 ORM 2 documentation</a> &raquo;</li> 
      </ul>
    </div>  

        <div class="document">
            <div class="documentwrapper">
                <div class="bodywrapper">

              <div class="body" >
                
  <div class="section" id="annotations-reference">
<h1>22. Annotations Reference<a class="headerlink" href="#annotations-reference" title="Permalink to this headline"></a></h1>
<p>In this chapter a reference of every Doctrine 2 Annotation is given
with short explanations on their context and usage.</p>
<div class="section" id="index">
<h2>22.1. Index<a class="headerlink" href="#index" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><a class="reference internal" href="#annref-column"><em>&#64;Column</em></a></li>
<li><a class="reference internal" href="#annref-column-result"><em>&#64;ColumnResult</em></a></li>
<li><a class="reference internal" href="#annref-changetrackingpolicy"><em>&#64;ChangeTrackingPolicy</em></a></li>
<li><a class="reference internal" href="#annref-discriminatorcolumn"><em>&#64;DiscriminatorColumn</em></a></li>
<li><a class="reference internal" href="#annref-discriminatormap"><em>&#64;DiscriminatorMap</em></a></li>
<li><a class="reference internal" href="#annref-entity"><em>&#64;Entity</em></a></li>
<li><a class="reference internal" href="#annref-entity-result"><em>&#64;EntityResult</em></a></li>
<li><a class="reference internal" href="#annref-field-result"><em>&#64;FieldResult</em></a></li>
<li><a class="reference internal" href="#annref-generatedvalue"><em>&#64;GeneratedValue</em></a></li>
<li><a class="reference internal" href="#annref-haslifecyclecallbacks"><em>&#64;HasLifecycleCallbacks</em></a></li>
<li><a class="reference internal" href="#annref-index"><em>&#64;Index</em></a></li>
<li><a class="reference internal" href="#annref-id"><em>&#64;Id</em></a></li>
<li><a class="reference internal" href="#annref-inheritancetype"><em>&#64;InheritanceType</em></a></li>
<li><a class="reference internal" href="#annref-joincolumn"><em>&#64;JoinColumn</em></a></li>
<li><a class="reference internal" href="#annref-joincolumns"><em>&#64;JoinColumns</em></a></li>
<li><a class="reference internal" href="#annref-jointable"><em>&#64;JoinTable</em></a></li>
<li><a class="reference internal" href="#annref-manytoone"><em>&#64;ManyToOne</em></a></li>
<li><a class="reference internal" href="#annref-manytomany"><em>&#64;ManyToMany</em></a></li>
<li><a class="reference internal" href="#annref-mappedsuperclass"><em>&#64;MappedSuperclass</em></a></li>
<li><a class="reference internal" href="#annref-named-native-query"><em>&#64;NamedNativeQuery</em></a></li>
<li><a class="reference internal" href="#annref-onetoone"><em>&#64;OneToOne</em></a></li>
<li><a class="reference internal" href="#annref-onetomany"><em>&#64;OneToMany</em></a></li>
<li><a class="reference internal" href="#annref-orderby"><em>&#64;OrderBy</em></a></li>
<li><a class="reference internal" href="#annref-postload"><em>&#64;PostLoad</em></a></li>
<li><a class="reference internal" href="#annref-postpersist"><em>&#64;PostPersist</em></a></li>
<li><a class="reference internal" href="#annref-postremove"><em>&#64;PostRemove</em></a></li>
<li><a class="reference internal" href="#annref-postupdate"><em>&#64;PostUpdate</em></a></li>
<li><a class="reference internal" href="#annref-prepersist"><em>&#64;PrePersist</em></a></li>
<li><a class="reference internal" href="#annref-preremove"><em>&#64;PreRemove</em></a></li>
<li><a class="reference internal" href="#annref-preupdate"><em>&#64;PreUpdate</em></a></li>
<li><a class="reference internal" href="#annref-sequencegenerator"><em>&#64;SequenceGenerator</em></a></li>
<li><a class="reference internal" href="#annref-sql-resultset-mapping"><em>&#64;SqlResultSetMapping</em></a></li>
<li><a class="reference internal" href="#annref-table"><em>&#64;Table</em></a></li>
<li><a class="reference internal" href="#annref-uniqueconstraint"><em>&#64;UniqueConstraint</em></a></li>
<li><a class="reference internal" href="#annref-version"><em>&#64;Version</em></a></li>
</ul>
</div>
<div class="section" id="reference">
<h2>22.2. Reference<a class="headerlink" href="#reference" title="Permalink to this headline"></a></h2>
<div class="section" id="column">
<span id="annref-column"></span><h3>22.2.1. &#64;Column<a class="headerlink" href="#column" title="Permalink to this headline"></a></h3>
<p>Marks an annotated instance variable as &#8220;persistent&#8221;. It has to be
inside the instance variables PHP DocBlock comment. Any value hold
inside this variable will be saved to and loaded from the database
as part of the lifecycle of the instance variables entity-class.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>type</strong>: Name of the Doctrine Type which is converted between PHP
and Database representation.</li>
</ul>
<p>Optional attributes:</p>
<ul>
<li><p class="first"><strong>name</strong>: By default the property name is used for the database
column name also, however the &#8216;name&#8217; attribute allows you to
determine the column name.</p>
</li>
<li><p class="first"><strong>length</strong>: Used by the &#8220;string&#8221; type to determine its maximum
length in the database. Doctrine does not validate the length of a
string values for you.</p>
</li>
<li><p class="first"><strong>precision</strong>: The precision for a decimal (exact numeric) column
(Applies only for decimal column)</p>
</li>
<li><p class="first"><strong>scale</strong>: The scale for a decimal (exact numeric) column (Applies
only for decimal column)</p>
</li>
<li><p class="first"><strong>unique</strong>: Boolean value to determine if the value of the column
should be unique across all rows of the underlying entities table.</p>
</li>
<li><p class="first"><strong>nullable</strong>: Determines if NULL values allowed for this column.</p>
</li>
<li><p class="first"><strong>columnDefinition</strong>: DDL SQL snippet that starts after the column
name and specifies the complete (non-portable!) column definition.
This attribute allows to make use of advanced RMDBS features.
However you should make careful use of this feature and the
consequences. SchemaTool will not detect changes on the column correctly
anymore if you use &#8220;columnDefinition&#8221;.</p>
<p>Additionally you should remember that the &#8220;type&#8221;
attribute still handles the conversion between PHP and Database
values. If you use this attribute on a column that is used for
joins between tables you should also take a look at
<a class="reference internal" href="#annref-joincolumn"><em>&#64;JoinColumn</em></a>.</p>
</li>
</ul>
<p>Examples:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Column(type=&quot;string&quot;, length=32, unique=true, nullable=false)</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$username</span><span class="p">;</span>

<span class="sd">/**</span>
<span class="sd"> * @Column(type=&quot;string&quot;, columnDefinition=&quot;CHAR(2) NOT NULL&quot;)</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$country</span><span class="p">;</span>

<span class="sd">/**</span>
<span class="sd"> * @Column(type=&quot;decimal&quot;, precision=2, scale=1)</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$height</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="columnresult">
<span id="annref-column-result"></span><h3>22.2.2. &#64;ColumnResult<a class="headerlink" href="#columnresult" title="Permalink to this headline"></a></h3>
<p>References name of a column in the SELECT clause of a SQL query.
Scalar result types can be included in the query result by specifying this annotation in the metadata.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: The name of a column in the SELECT clause of a SQL query</li>
</ul>
</div>
<div class="section" id="changetrackingpolicy">
<span id="annref-changetrackingpolicy"></span><h3>22.2.3. &#64;ChangeTrackingPolicy<a class="headerlink" href="#changetrackingpolicy" title="Permalink to this headline"></a></h3>
<p>The Change Tracking Policy annotation allows to specify how the
Doctrine 2 UnitOfWork should detect changes in properties of
entities during flush. By default each entity is checked according
to a deferred implicit strategy, which means upon flush UnitOfWork
compares all the properties of an entity to a previously stored
snapshot. This works out of the box, however you might want to
tweak the flush performance where using another change tracking
policy is an interesting option.</p>
<p>The <a class="reference internal" href="change-tracking-policies.html"><em>details on all the available change tracking policies</em></a>
can be found in the configuration section.</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @ChangeTrackingPolicy(&quot;DEFERRED_IMPLICIT&quot;)</span>
<span class="sd"> * @ChangeTrackingPolicy(&quot;DEFERRED_EXPLICIT&quot;)</span>
<span class="sd"> * @ChangeTrackingPolicy(&quot;NOTIFY&quot;)</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span> <span class="p">{}</span>
</pre></div>
</div>
</div>
<div class="section" id="discriminatorcolumn">
<span id="annref-discriminatorcolumn"></span><h3>22.2.4. &#64;DiscriminatorColumn<a class="headerlink" href="#discriminatorcolumn" title="Permalink to this headline"></a></h3>
<p>This annotation is a required annotation for the topmost/super
class of an inheritance hierarchy. It specifies the details of the
column which saves the name of the class, which the entity is
actually instantiated as.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: The column name of the discriminator. This name is also
used during Array hydration as key to specify the class-name.</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>type</strong>: By default this is string.</li>
<li><strong>length</strong>: By default this is 255.</li>
</ul>
</div>
<div class="section" id="discriminatormap">
<span id="annref-discriminatormap"></span><h3>22.2.5. &#64;DiscriminatorMap<a class="headerlink" href="#discriminatormap" title="Permalink to this headline"></a></h3>
<p>The discriminator map is a required annotation on the
top-most/super class in an inheritance hierarchy. It takes an array
as only argument which defines which class should be saved under
which name in the database. Keys are the database value and values
are the classes, either as fully- or as unqualified class names
depending if the classes are in the namespace or not.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @InheritanceType(&quot;JOINED&quot;)</span>
<span class="sd"> * @DiscriminatorColumn(name=&quot;discr&quot;, type=&quot;string&quot;)</span>
<span class="sd"> * @DiscriminatorMap({&quot;person&quot; = &quot;Person&quot;, &quot;employee&quot; = &quot;Employee&quot;})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="entity">
<span id="annref-entity"></span><h3>22.2.6. &#64;Entity<a class="headerlink" href="#entity" title="Permalink to this headline"></a></h3>
<p>Required annotation to mark a PHP class as Entity. Doctrine manages
the persistence of all classes marked as entity.</p>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>repositoryClass</strong>: Specifies the FQCN of a subclass of the
EntityRepository. Use of repositories for entities is encouraged to keep
specialized DQL and SQL operations separated from the Model/Domain
Layer.</li>
<li><strong>readOnly</strong>: (&gt;= 2.1) Specifies that this entity is marked as read only and not
considered for change-tracking. Entities of this type can be persisted
and removed though.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity(repositoryClass=&quot;MyProject\UserRepository&quot;)</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span>
<span class="p">{</span>
    <span class="c1">//...</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="entityresult">
<span id="annref-entity-result"></span><h3>22.2.7. &#64;EntityResult<a class="headerlink" href="#entityresult" title="Permalink to this headline"></a></h3>
<p>References an entity in the SELECT clause of a SQL query.
If this annotation is used, the SQL statement should select all of the columns that are mapped to the entity object.
This should include foreign key columns to related entities.
The results obtained when insufficient data is available are undefined.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>entityClass</strong>: The class of the result.</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>fields</strong>: Array of &#64;FieldResult, Maps the columns specified in the SELECT list of the query to the properties or fields of the entity class.</li>
<li><strong>discriminatorColumn</strong>: Specifies the column name of the column in the SELECT list that is used to determine the type of the entity instance.</li>
</ul>
</div>
<div class="section" id="fieldresult">
<span id="annref-field-result"></span><h3>22.2.8. &#64;FieldResult<a class="headerlink" href="#fieldresult" title="Permalink to this headline"></a></h3>
<p>Is used to map the columns specified in the SELECT list of the query to the properties or fields of the entity class.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: Name of the persistent field or property of the class.</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>column</strong>: Name of the column in the SELECT clause.</li>
</ul>
</div>
<div class="section" id="generatedvalue">
<span id="annref-generatedvalue"></span><h3>22.2.9. &#64;GeneratedValue<a class="headerlink" href="#generatedvalue" title="Permalink to this headline"></a></h3>
<p>Specifies which strategy is used for identifier generation for an
instance variable which is annotated by <a class="reference internal" href="#annref-id"><em>&#64;Id</em></a>. This
annotation is optional and only has meaning when used in
conjunction with &#64;Id.</p>
<p>If this annotation is not specified with &#64;Id the NONE strategy is
used as default.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>strategy</strong>: Set the name of the identifier generation strategy.
Valid values are AUTO, SEQUENCE, TABLE, IDENTITY, UUID, CUSTOM and NONE.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Id</span>
<span class="sd"> * @Column(type=&quot;integer&quot;)</span>
<span class="sd"> * @GeneratedValue(strategy=&quot;IDENTITY&quot;)</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$id</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="haslifecyclecallbacks">
<span id="annref-haslifecyclecallbacks"></span><h3>22.2.10. &#64;HasLifecycleCallbacks<a class="headerlink" href="#haslifecyclecallbacks" title="Permalink to this headline"></a></h3>
<p>Annotation which has to be set on the entity-class PHP DocBlock to
notify Doctrine that this entity has entity life-cycle callback
annotations set on at least one of its methods. Using &#64;PostLoad,
&#64;PrePersist, &#64;PostPersist, &#64;PreRemove, &#64;PostRemove, &#64;PreUpdate or
&#64;PostUpdate without this marker annotation will make Doctrine
ignore the callbacks.</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @HasLifecycleCallbacks</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span>
<span class="p">{</span>
    <span class="sd">/**</span>
<span class="sd">     * @PostPersist</span>
<span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">sendOptinMail</span><span class="p">()</span> <span class="p">{}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="annref-index">
<span id="id1"></span><h3>22.2.11. &#64;Index<a class="headerlink" href="#annref-index" title="Permalink to this headline"></a></h3>
<p>Annotation is used inside the <a class="reference internal" href="#annref-table"><em>&#64;Table</em></a> annotation on
the entity-class level. It allows to hint the SchemaTool to
generate a database index on the specified table columns. It only
has meaning in the SchemaTool schema generation context.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: Name of the Index</li>
<li><strong>columns</strong>: Array of columns.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @Table(name=&quot;ecommerce_products&quot;,indexes={@Index(name=&quot;search_idx&quot;, columns={&quot;name&quot;, &quot;email&quot;})})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">ECommerceProduct</span>
<span class="p">{</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="annref-id">
<span id="id"></span><h3>22.2.12. &#64;Id<a class="headerlink" href="#annref-id" title="Permalink to this headline"></a></h3>
<p>The annotated instance variable will be marked as entity
identifier, the primary key in the database. This annotation is a
marker only and has no required or optional attributes. For
entities that have multiple identifier columns each column has to
be marked with &#64;Id.</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Id</span>
<span class="sd"> * @Column(type=&quot;integer&quot;)</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$id</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="inheritancetype">
<span id="annref-inheritancetype"></span><h3>22.2.13. &#64;InheritanceType<a class="headerlink" href="#inheritancetype" title="Permalink to this headline"></a></h3>
<p>In an inheritance hierarchy you have to use this annotation on the
topmost/super class to define which strategy should be used for
inheritance. Currently Single Table and Class Table Inheritance are
supported.</p>
<p>This annotation has always been used in conjunction with the
<a class="reference internal" href="#annref-discriminatormap"><em>&#64;DiscriminatorMap</em></a> and
<a class="reference internal" href="#annref-discriminatorcolumn"><em>&#64;DiscriminatorColumn</em></a> annotations.</p>
<p>Examples:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @InheritanceType(&quot;SINGLE_TABLE&quot;)</span>
<span class="sd"> * @DiscriminatorColumn(name=&quot;discr&quot;, type=&quot;string&quot;)</span>
<span class="sd"> * @DiscriminatorMap({&quot;person&quot; = &quot;Person&quot;, &quot;employee&quot; = &quot;Employee&quot;})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>

<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @InheritanceType(&quot;JOINED&quot;)</span>
<span class="sd"> * @DiscriminatorColumn(name=&quot;discr&quot;, type=&quot;string&quot;)</span>
<span class="sd"> * @DiscriminatorMap({&quot;person&quot; = &quot;Person&quot;, &quot;employee&quot; = &quot;Employee&quot;})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="joincolumn">
<span id="annref-joincolumn"></span><h3>22.2.14. &#64;JoinColumn<a class="headerlink" href="#joincolumn" title="Permalink to this headline"></a></h3>
<p>This annotation is used in the context of relations in
<a class="reference internal" href="#annref-manytoone"><em>&#64;ManyToOne</em></a>, <a class="reference internal" href="#annref-onetoone"><em>&#64;OneToOne</em></a> fields
and in the Context of <a class="reference internal" href="#annref-jointable"><em>&#64;JoinTable</em></a> nested inside
a &#64;ManyToMany. This annotation is not required. If its not
specified the attributes <em>name</em> and <em>referencedColumnName</em> are
inferred from the table and primary key names.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: Column name that holds the foreign key identifier for
this relation. In the context of &#64;JoinTable it specifies the column
name in the join table.</li>
<li><strong>referencedColumnName</strong>: Name of the primary key identifier that
is used for joining of this relation.</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>unique</strong>: Determines if this relation exclusive between the
affected entities and should be enforced so on the database
constraint level. Defaults to false.</li>
<li><strong>nullable</strong>: Determine if the related entity is required, or if
null is an allowed state for the relation. Defaults to true.</li>
<li><strong>onDelete</strong>: Cascade Action (Database-level)</li>
<li><strong>columnDefinition</strong>: DDL SQL snippet that starts after the column
name and specifies the complete (non-portable!) column definition.
This attribute allows to make use of advanced RMDBS features. Using
this attribute on &#64;JoinColumn is necessary if you need slightly
different column definitions for joining columns, for example
regarding NULL/NOT NULL defaults. However by default a
&#8220;columnDefinition&#8221; attribute on <a class="reference internal" href="#annref-column"><em>&#64;Column</em></a> also sets
the related &#64;JoinColumn&#8217;s columnDefinition. This is necessary to
make foreign keys work.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @OneToOne(targetEntity=&quot;Customer&quot;)</span>
<span class="sd"> * @JoinColumn(name=&quot;customer_id&quot;, referencedColumnName=&quot;id&quot;)</span>
<span class="sd"> */</span>
<span class="k">private</span> <span class="nv">$customer</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="joincolumns">
<span id="annref-joincolumns"></span><h3>22.2.15. &#64;JoinColumns<a class="headerlink" href="#joincolumns" title="Permalink to this headline"></a></h3>
<p>An array of &#64;JoinColumn annotations for a
<a class="reference internal" href="#annref-manytoone"><em>&#64;ManyToOne</em></a> or <a class="reference internal" href="#annref-onetoone"><em>&#64;OneToOne</em></a>
relation with an entity that has multiple identifiers.</p>
</div>
<div class="section" id="jointable">
<span id="annref-jointable"></span><h3>22.2.16. &#64;JoinTable<a class="headerlink" href="#jointable" title="Permalink to this headline"></a></h3>
<p>Using <a class="reference internal" href="#annref-onetomany"><em>&#64;OneToMany</em></a> or
<a class="reference internal" href="#annref-manytomany"><em>&#64;ManyToMany</em></a> on the owning side of the relation
requires to specify the &#64;JoinTable annotation which describes the
details of the database join table. If you do not specify
&#64;JoinTable on these relations reasonable mapping defaults apply
using the affected table and the column names.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: Database name of the join-table</li>
<li><strong>joinColumns</strong>: An array of &#64;JoinColumn annotations describing the
join-relation between the owning entities table and the join table.</li>
<li><strong>inverseJoinColumns</strong>: An array of &#64;JoinColumn annotations
describing the join-relation between the inverse entities table and
the join table.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @ManyToMany(targetEntity=&quot;Phonenumber&quot;)</span>
<span class="sd"> * @JoinTable(name=&quot;users_phonenumbers&quot;,</span>
<span class="sd"> *      joinColumns={@JoinColumn(name=&quot;user_id&quot;, referencedColumnName=&quot;id&quot;)},</span>
<span class="sd"> *      inverseJoinColumns={@JoinColumn(name=&quot;phonenumber_id&quot;, referencedColumnName=&quot;id&quot;, unique=true)}</span>
<span class="sd"> * )</span>
<span class="sd"> */</span>
<span class="k">public</span> <span class="nv">$phonenumbers</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="manytoone">
<span id="annref-manytoone"></span><h3>22.2.17. &#64;ManyToOne<a class="headerlink" href="#manytoone" title="Permalink to this headline"></a></h3>
<p>Defines that the annotated instance variable holds a reference that
describes a many-to-one relationship between two entities.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>targetEntity</strong>: FQCN of the referenced target entity. Can be the
unqualified class name if both classes are in the same namespace.
<em>IMPORTANT:</em> No leading backslash!</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>cascade</strong>: Cascade Option</li>
<li><strong>fetch</strong>: One of LAZY or EAGER</li>
<li>inversedBy - The inversedBy attribute designates the field in
the entity that is the inverse side of the relationship.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @ManyToOne(targetEntity=&quot;Cart&quot;, cascade={&quot;all&quot;}, fetch=&quot;EAGER&quot;)</span>
<span class="sd"> */</span>
<span class="k">private</span> <span class="nv">$cart</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="manytomany">
<span id="annref-manytomany"></span><h3>22.2.18. &#64;ManyToMany<a class="headerlink" href="#manytomany" title="Permalink to this headline"></a></h3>
<p>Defines an instance variable holds a many-to-many relationship
between two entities. <a class="reference internal" href="#annref-jointable"><em>&#64;JoinTable</em></a> is an
additional, optional annotation that has reasonable default
configuration values using the table and names of the two related
entities.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>targetEntity</strong>: FQCN of the referenced target entity. Can be the
unqualified class name if both classes are in the same namespace.
<em>IMPORTANT:</em> No leading backslash!</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>mappedBy</strong>: This option specifies the property name on the
targetEntity that is the owning side of this relation. Its a
required attribute for the inverse side of a relationship.</li>
<li><strong>inversedBy</strong>: The inversedBy attribute designates the field in the
entity that is the inverse side of the relationship.</li>
<li><strong>cascade</strong>: Cascade Option</li>
<li><strong>fetch</strong>: One of LAZY, EXTRA_LAZY or EAGER</li>
<li><strong>indexBy</strong>: Index the collection by a field on the target entity.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For ManyToMany bidirectional relationships either side may
be the owning side (the side that defines the &#64;JoinTable and/or
does not make use of the mappedBy attribute, thus using a default
join table).</p>
</div>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * Owning Side</span>
<span class="sd"> *</span>
<span class="sd"> * @ManyToMany(targetEntity=&quot;Group&quot;, inversedBy=&quot;features&quot;)</span>
<span class="sd"> * @JoinTable(name=&quot;user_groups&quot;,</span>
<span class="sd"> *      joinColumns={@JoinColumn(name=&quot;user_id&quot;, referencedColumnName=&quot;id&quot;)},</span>
<span class="sd"> *      inverseJoinColumns={@JoinColumn(name=&quot;group_id&quot;, referencedColumnName=&quot;id&quot;)}</span>
<span class="sd"> *      )</span>
<span class="sd"> */</span>
<span class="k">private</span> <span class="nv">$groups</span><span class="p">;</span>

<span class="sd">/**</span>
<span class="sd"> * Inverse Side</span>
<span class="sd"> *</span>
<span class="sd"> * @ManyToMany(targetEntity=&quot;User&quot;, mappedBy=&quot;groups&quot;)</span>
<span class="sd"> */</span>
<span class="k">private</span> <span class="nv">$features</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="mappedsuperclass">
<span id="annref-mappedsuperclass"></span><h3>22.2.19. &#64;MappedSuperclass<a class="headerlink" href="#mappedsuperclass" title="Permalink to this headline"></a></h3>
<p>An mapped superclass is an abstract or concrete class that provides
persistent entity state and mapping information for its subclasses,
but which is not itself an entity. This annotation is specified on
the Class docblock and has no additional attributes.</p>
<p>The &#64;MappedSuperclass annotation cannot be used in conjunction with
&#64;Entity. See the Inheritance Mapping section for
<a class="reference internal" href="inheritance-mapping.html"><em>more details on the restrictions of mapped superclasses</em></a>.</p>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>repositoryClass</strong>: (&gt;= 2.2) Specifies the FQCN of a subclass of the EntityRepository.
That will be inherited for all subclasses of that Mapped Superclass.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @MappedSuperclass</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">MappedSuperclassBase</span>
<span class="p">{</span>
    <span class="c1">// ... fields and methods</span>
<span class="p">}</span>

<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">EntitySubClassFoo</span> <span class="k">extends</span> <span class="nx">MappedSuperclassBase</span>
<span class="p">{</span>
    <span class="c1">// ... fields and methods</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="namednativequery">
<span id="annref-named-native-query"></span><h3>22.2.20. &#64;NamedNativeQuery<a class="headerlink" href="#namednativequery" title="Permalink to this headline"></a></h3>
<p>Is used to specify a native SQL named query.
The NamedNativeQuery annotation can be applied to an entity or mapped superclass.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: The name used to refer to the query with the EntityManager methods that create query objects.</li>
<li><strong>query</strong>: The SQL query string.</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>resultClass</strong>: The class of the result.</li>
<li><strong>resultSetMapping</strong>: The name of a SqlResultSetMapping, as defined in metadata.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @NamedNativeQueries({</span>
<span class="sd"> *      @NamedNativeQuery(</span>
<span class="sd"> *          name            = &quot;fetchJoinedAddress&quot;,</span>
<span class="sd"> *          resultSetMapping= &quot;mappingJoinedAddress&quot;,</span>
<span class="sd"> *          query           = &quot;SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?&quot;</span>
<span class="sd"> *      ),</span>
<span class="sd"> * })</span>
<span class="sd"> * @SqlResultSetMappings({</span>
<span class="sd"> *      @SqlResultSetMapping(</span>
<span class="sd"> *          name    = &quot;mappingJoinedAddress&quot;,</span>
<span class="sd"> *          entities= {</span>
<span class="sd"> *              @EntityResult(</span>
<span class="sd"> *                  entityClass = &quot;__CLASS__&quot;,</span>
<span class="sd"> *                  fields      = {</span>
<span class="sd"> *                      @FieldResult(name = &quot;id&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;name&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;status&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;address.zip&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;address.city&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;address.country&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;address.id&quot;, column = &quot;a_id&quot;),</span>
<span class="sd"> *                  }</span>
<span class="sd"> *              )</span>
<span class="sd"> *          }</span>
<span class="sd"> *      )</span>
<span class="sd"> * })</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span>
<span class="p">{</span>
    <span class="sd">/** @Id @Column(type=&quot;integer&quot;) @GeneratedValue */</span>
    <span class="k">public</span> <span class="nv">$id</span><span class="p">;</span>

    <span class="sd">/** @Column(type=&quot;string&quot;, length=50, nullable=true) */</span>
    <span class="k">public</span> <span class="nv">$status</span><span class="p">;</span>

    <span class="sd">/** @Column(type=&quot;string&quot;, length=255, unique=true) */</span>
    <span class="k">public</span> <span class="nv">$username</span><span class="p">;</span>

    <span class="sd">/** @Column(type=&quot;string&quot;, length=255) */</span>
    <span class="k">public</span> <span class="nv">$name</span><span class="p">;</span>

    <span class="sd">/** @OneToOne(targetEntity=&quot;Address&quot;) */</span>
    <span class="k">public</span> <span class="nv">$address</span><span class="p">;</span>

    <span class="c1">// ....</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="onetoone">
<span id="annref-onetoone"></span><h3>22.2.21. &#64;OneToOne<a class="headerlink" href="#onetoone" title="Permalink to this headline"></a></h3>
<p>The &#64;OneToOne annotation works almost exactly as the
<a class="reference internal" href="#annref-manytoone"><em>&#64;ManyToOne</em></a> with one additional option that can
be specified. The configuration defaults for
<a class="reference internal" href="#annref-joincolumn"><em>&#64;JoinColumn</em></a> using the target entity table and
primary key column names apply here too.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>targetEntity</strong>: FQCN of the referenced target entity. Can be the
unqualified class name if both classes are in the same namespace.
<em>IMPORTANT:</em> No leading backslash!</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>cascade</strong>: Cascade Option</li>
<li><strong>fetch</strong>: One of LAZY or EAGER</li>
<li><strong>orphanRemoval</strong>: Boolean that specifies if orphans, inverse
OneToOne entities that are not connected to any owning instance,
should be removed by Doctrine. Defaults to false.</li>
<li><strong>inversedBy</strong>: The inversedBy attribute designates the field in the
entity that is the inverse side of the relationship.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @OneToOne(targetEntity=&quot;Customer&quot;)</span>
<span class="sd"> * @JoinColumn(name=&quot;customer_id&quot;, referencedColumnName=&quot;id&quot;)</span>
<span class="sd"> */</span>
<span class="k">private</span> <span class="nv">$customer</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="onetomany">
<span id="annref-onetomany"></span><h3>22.2.22. &#64;OneToMany<a class="headerlink" href="#onetomany" title="Permalink to this headline"></a></h3>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>targetEntity</strong>: FQCN of the referenced target entity. Can be the
unqualified class name if both classes are in the same namespace.
<em>IMPORTANT:</em> No leading backslash!</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>cascade</strong>: Cascade Option</li>
<li><strong>orphanRemoval</strong>: Boolean that specifies if orphans, inverse
OneToOne entities that are not connected to any owning instance,
should be removed by Doctrine. Defaults to false.</li>
<li><strong>mappedBy</strong>: This option specifies the property name on the
targetEntity that is the owning side of this relation. Its a
required attribute for the inverse side of a relationship.</li>
<li><strong>fetch</strong>: One of LAZY, EXTRA_LAZY or EAGER.</li>
<li><strong>indexBy</strong>: Index the collection by a field on the target entity.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @OneToMany(targetEntity=&quot;Phonenumber&quot;, mappedBy=&quot;user&quot;, cascade={&quot;persist&quot;, &quot;remove&quot;, &quot;merge&quot;}, orphanRemoval=true)</span>
<span class="sd"> */</span>
<span class="k">public</span> <span class="nv">$phonenumbers</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="orderby">
<span id="annref-orderby"></span><h3>22.2.23. &#64;OrderBy<a class="headerlink" href="#orderby" title="Permalink to this headline"></a></h3>
<p>Optional annotation that can be specified with a
<a class="reference internal" href="#annref-manytomany"><em>&#64;ManyToMany</em></a> or <a class="reference internal" href="#annref-onetomany"><em>&#64;OneToMany</em></a>
annotation to specify by which criteria the collection should be
retrieved from the database by using an ORDER BY clause.</p>
<p>This annotation requires a single non-attributed value with an DQL
snippet:</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @ManyToMany(targetEntity=&quot;Group&quot;)</span>
<span class="sd"> * @OrderBy({&quot;name&quot; = &quot;ASC&quot;})</span>
<span class="sd"> */</span>
<span class="k">private</span> <span class="nv">$groups</span><span class="p">;</span>
</pre></div>
</div>
<p>The DQL Snippet in OrderBy is only allowed to consist of
unqualified, unquoted field names and of an optional ASC/DESC
positional statement. Multiple Fields are separated by a comma (,).
The referenced field names have to exist on the <tt class="docutils literal"><span class="pre">targetEntity</span></tt>
class of the <tt class="docutils literal"><span class="pre">&#64;ManyToMany</span></tt> or <tt class="docutils literal"><span class="pre">&#64;OneToMany</span></tt> annotation.</p>
</div>
<div class="section" id="postload">
<span id="annref-postload"></span><h3>22.2.24. &#64;PostLoad<a class="headerlink" href="#postload" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PostLoad event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="postpersist">
<span id="annref-postpersist"></span><h3>22.2.25. &#64;PostPersist<a class="headerlink" href="#postpersist" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PostPersist event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="postremove">
<span id="annref-postremove"></span><h3>22.2.26. &#64;PostRemove<a class="headerlink" href="#postremove" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PostRemove event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="postupdate">
<span id="annref-postupdate"></span><h3>22.2.27. &#64;PostUpdate<a class="headerlink" href="#postupdate" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PostUpdate event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="prepersist">
<span id="annref-prepersist"></span><h3>22.2.28. &#64;PrePersist<a class="headerlink" href="#prepersist" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PrePersist event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="preremove">
<span id="annref-preremove"></span><h3>22.2.29. &#64;PreRemove<a class="headerlink" href="#preremove" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PreRemove event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="preupdate">
<span id="annref-preupdate"></span><h3>22.2.30. &#64;PreUpdate<a class="headerlink" href="#preupdate" title="Permalink to this headline"></a></h3>
<p>Marks a method on the entity to be called as a &#64;PreUpdate event.
Only works with &#64;HasLifecycleCallbacks in the entity class PHP
DocBlock.</p>
</div>
<div class="section" id="sequencegenerator">
<span id="annref-sequencegenerator"></span><h3>22.2.31. &#64;SequenceGenerator<a class="headerlink" href="#sequencegenerator" title="Permalink to this headline"></a></h3>
<p>For the use with &#64;generatedValue(strategy=&#8221;SEQUENCE&#8221;) this
annotation allows to specify details about the sequence, such as
the increment size and initial values of the sequence.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>sequenceName</strong>: Name of the sequence</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>allocationSize</strong>: Increment the sequence by the allocation size
when its fetched. A value larger than 1 allows to optimize for
scenarios where you create more than one new entity per request.
Defaults to 10</li>
<li><strong>initialValue</strong>: Where does the sequence start, defaults to 1.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Id</span>
<span class="sd"> * @GeneratedValue(strategy=&quot;SEQUENCE&quot;)</span>
<span class="sd"> * @Column(type=&quot;integer&quot;)</span>
<span class="sd"> * @SequenceGenerator(sequenceName=&quot;tablename_seq&quot;, initialValue=1, allocationSize=100)</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$id</span> <span class="o">=</span> <span class="k">null</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="sqlresultsetmapping">
<span id="annref-sql-resultset-mapping"></span><h3>22.2.32. &#64;SqlResultSetMapping<a class="headerlink" href="#sqlresultsetmapping" title="Permalink to this headline"></a></h3>
<p>The SqlResultSetMapping annotation is used to specify the mapping of the result of a native SQL query.
The SqlResultSetMapping annotation can be applied to an entity or mapped superclass.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: The name given to the result set mapping, and used to refer to it in the methods of the Query API.</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>entities</strong>: Array of &#64;EntityResult, Specifies the result set mapping to entities.</li>
<li><strong>columns</strong>: Array of &#64;ColumnResult, Specifies the result set mapping to scalar values.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @NamedNativeQueries({</span>
<span class="sd"> *      @NamedNativeQuery(</span>
<span class="sd"> *          name            = &quot;fetchUserPhonenumberCount&quot;,</span>
<span class="sd"> *          resultSetMapping= &quot;mappingUserPhonenumberCount&quot;,</span>
<span class="sd"> *          query           = &quot;SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username&quot;</span>
<span class="sd"> *      ),</span>
<span class="sd"> *      @NamedNativeQuery(</span>
<span class="sd"> *          name            = &quot;fetchMultipleJoinsEntityResults&quot;,</span>
<span class="sd"> *          resultSetMapping= &quot;mappingMultipleJoinsEntityResults&quot;,</span>
<span class="sd"> *          query           = &quot;SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username&quot;</span>
<span class="sd"> *      ),</span>
<span class="sd"> * })</span>
<span class="sd"> * @SqlResultSetMappings({</span>
<span class="sd"> *      @SqlResultSetMapping(</span>
<span class="sd"> *          name    = &quot;mappingUserPhonenumberCount&quot;,</span>
<span class="sd"> *          entities= {</span>
<span class="sd"> *              @EntityResult(</span>
<span class="sd"> *                  entityClass = &quot;User&quot;,</span>
<span class="sd"> *                  fields      = {</span>
<span class="sd"> *                      @FieldResult(name = &quot;id&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;name&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;status&quot;),</span>
<span class="sd"> *                  }</span>
<span class="sd"> *              )</span>
<span class="sd"> *          },</span>
<span class="sd"> *          columns = {</span>
<span class="sd"> *              @ColumnResult(&quot;numphones&quot;)</span>
<span class="sd"> *          }</span>
<span class="sd"> *      ),</span>
<span class="sd"> *      @SqlResultSetMapping(</span>
<span class="sd"> *          name    = &quot;mappingMultipleJoinsEntityResults&quot;,</span>
<span class="sd"> *          entities= {</span>
<span class="sd"> *              @EntityResult(</span>
<span class="sd"> *                  entityClass = &quot;__CLASS__&quot;,</span>
<span class="sd"> *                  fields      = {</span>
<span class="sd"> *                      @FieldResult(name = &quot;id&quot;,       column=&quot;u_id&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;name&quot;,     column=&quot;u_name&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;status&quot;,   column=&quot;u_status&quot;),</span>
<span class="sd"> *                  }</span>
<span class="sd"> *              ),</span>
<span class="sd"> *              @EntityResult(</span>
<span class="sd"> *                  entityClass = &quot;Address&quot;,</span>
<span class="sd"> *                  fields      = {</span>
<span class="sd"> *                      @FieldResult(name = &quot;id&quot;,       column=&quot;a_id&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;zip&quot;,      column=&quot;a_zip&quot;),</span>
<span class="sd"> *                      @FieldResult(name = &quot;country&quot;,  column=&quot;a_country&quot;),</span>
<span class="sd"> *                  }</span>
<span class="sd"> *              )</span>
<span class="sd"> *          },</span>
<span class="sd"> *          columns = {</span>
<span class="sd"> *              @ColumnResult(&quot;numphones&quot;)</span>
<span class="sd"> *          }</span>
<span class="sd"> *      )</span>
<span class="sd"> *})</span>
<span class="sd"> */</span>
 <span class="k">class</span> <span class="nc">User</span>
<span class="p">{</span>
    <span class="sd">/** @Id @Column(type=&quot;integer&quot;) @GeneratedValue */</span>
    <span class="k">public</span> <span class="nv">$id</span><span class="p">;</span>

    <span class="sd">/** @Column(type=&quot;string&quot;, length=50, nullable=true) */</span>
    <span class="k">public</span> <span class="nv">$status</span><span class="p">;</span>

    <span class="sd">/** @Column(type=&quot;string&quot;, length=255, unique=true) */</span>
    <span class="k">public</span> <span class="nv">$username</span><span class="p">;</span>

    <span class="sd">/** @Column(type=&quot;string&quot;, length=255) */</span>
    <span class="k">public</span> <span class="nv">$name</span><span class="p">;</span>

    <span class="sd">/** @OneToMany(targetEntity=&quot;Phonenumber&quot;) */</span>
    <span class="k">public</span> <span class="nv">$phonenumbers</span><span class="p">;</span>

    <span class="sd">/** @OneToOne(targetEntity=&quot;Address&quot;) */</span>
    <span class="k">public</span> <span class="nv">$address</span><span class="p">;</span>

    <span class="c1">// ....</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="table">
<span id="annref-table"></span><h3>22.2.33. &#64;Table<a class="headerlink" href="#table" title="Permalink to this headline"></a></h3>
<p>Annotation describes the table an entity is persisted in. It is
placed on the entity-class PHP DocBlock and is optional. If it is
not specified the table name will default to the entities
unqualified classname.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: Name of the table</li>
</ul>
<p>Optional attributes:</p>
<ul class="simple">
<li><strong>indexes</strong>: Array of &#64;Index annotations</li>
<li><strong>uniqueConstraints</strong>: Array of &#64;UniqueConstraint annotations.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @Table(name=&quot;user&quot;,</span>
<span class="sd"> *      uniqueConstraints={@UniqueConstraint(name=&quot;user_unique&quot;,columns={&quot;username&quot;})},</span>
<span class="sd"> *      indexes={@Index(name=&quot;user_idx&quot;, columns={&quot;email&quot;})}</span>
<span class="sd"> * )</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span> <span class="p">{</span> <span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="uniqueconstraint">
<span id="annref-uniqueconstraint"></span><h3>22.2.34. &#64;UniqueConstraint<a class="headerlink" href="#uniqueconstraint" title="Permalink to this headline"></a></h3>
<p>Annotation is used inside the <a class="reference internal" href="#annref-table"><em>&#64;Table</em></a> annotation on
the entity-class level. It allows to hint the SchemaTool to
generate a database unique constraint on the specified table
columns. It only has meaning in the SchemaTool schema generation
context.</p>
<p>Required attributes:</p>
<ul class="simple">
<li><strong>name</strong>: Name of the Index</li>
<li><strong>columns</strong>: Array of columns.</li>
</ul>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @Table(name=&quot;ecommerce_products&quot;,uniqueConstraints={@UniqueConstraint(name=&quot;search_idx&quot;, columns={&quot;name&quot;, &quot;email&quot;})})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">ECommerceProduct</span>
<span class="p">{</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="version">
<span id="annref-version"></span><h3>22.2.35. &#64;Version<a class="headerlink" href="#version" title="Permalink to this headline"></a></h3>
<p>Marker annotation that defines a specified column as version
attribute used in an optimistic locking scenario. It only works on
<a class="reference internal" href="#annref-column"><em>&#64;Column</em></a> annotations that have the type integer or
datetime. Combining &#64;Version with <a class="reference internal" href="#annref-id"><em>&#64;Id</em></a> is not supported.</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/**</span>
<span class="sd"> * @Column(type=&quot;integer&quot;)</span>
<span class="sd"> * @Version</span>
<span class="sd"> */</span>
<span class="k">protected</span> <span class="nv">$version</span><span class="p">;</span>
</pre></div>
</div>
</div>
</div>
</div>


              </div>
                </div>

            </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
             
            <div id="searchbox" style="">
              <h3>Search</h3>
                <form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="text" name="q" size="18">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>
            </div>
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference internal" href="#">22. Annotations Reference</a><ul>
<li><a class="reference internal" href="#index">22.1. Index</a></li>
<li><a class="reference internal" href="#reference">22.2. Reference</a><ul>
<li><a class="reference internal" href="#column">22.2.1. &#64;Column</a></li>
<li><a class="reference internal" href="#columnresult">22.2.2. &#64;ColumnResult</a></li>
<li><a class="reference internal" href="#changetrackingpolicy">22.2.3. &#64;ChangeTrackingPolicy</a></li>
<li><a class="reference internal" href="#discriminatorcolumn">22.2.4. &#64;DiscriminatorColumn</a></li>
<li><a class="reference internal" href="#discriminatormap">22.2.5. &#64;DiscriminatorMap</a></li>
<li><a class="reference internal" href="#entity">22.2.6. &#64;Entity</a></li>
<li><a class="reference internal" href="#entityresult">22.2.7. &#64;EntityResult</a></li>
<li><a class="reference internal" href="#fieldresult">22.2.8. &#64;FieldResult</a></li>
<li><a class="reference internal" href="#generatedvalue">22.2.9. &#64;GeneratedValue</a></li>
<li><a class="reference internal" href="#haslifecyclecallbacks">22.2.10. &#64;HasLifecycleCallbacks</a></li>
<li><a class="reference internal" href="#annref-index">22.2.11. &#64;Index</a></li>
<li><a class="reference internal" href="#annref-id">22.2.12. &#64;Id</a></li>
<li><a class="reference internal" href="#inheritancetype">22.2.13. &#64;InheritanceType</a></li>
<li><a class="reference internal" href="#joincolumn">22.2.14. &#64;JoinColumn</a></li>
<li><a class="reference internal" href="#joincolumns">22.2.15. &#64;JoinColumns</a></li>
<li><a class="reference internal" href="#jointable">22.2.16. &#64;JoinTable</a></li>
<li><a class="reference internal" href="#manytoone">22.2.17. &#64;ManyToOne</a></li>
<li><a class="reference internal" href="#manytomany">22.2.18. &#64;ManyToMany</a></li>
<li><a class="reference internal" href="#mappedsuperclass">22.2.19. &#64;MappedSuperclass</a></li>
<li><a class="reference internal" href="#namednativequery">22.2.20. &#64;NamedNativeQuery</a></li>
<li><a class="reference internal" href="#onetoone">22.2.21. &#64;OneToOne</a></li>
<li><a class="reference internal" href="#onetomany">22.2.22. &#64;OneToMany</a></li>
<li><a class="reference internal" href="#orderby">22.2.23. &#64;OrderBy</a></li>
<li><a class="reference internal" href="#postload">22.2.24. &#64;PostLoad</a></li>
<li><a class="reference internal" href="#postpersist">22.2.25. &#64;PostPersist</a></li>
<li><a class="reference internal" href="#postremove">22.2.26. &#64;PostRemove</a></li>
<li><a class="reference internal" href="#postupdate">22.2.27. &#64;PostUpdate</a></li>
<li><a class="reference internal" href="#prepersist">22.2.28. &#64;PrePersist</a></li>
<li><a class="reference internal" href="#preremove">22.2.29. &#64;PreRemove</a></li>
<li><a class="reference internal" href="#preupdate">22.2.30. &#64;PreUpdate</a></li>
<li><a class="reference internal" href="#sequencegenerator">22.2.31. &#64;SequenceGenerator</a></li>
<li><a class="reference internal" href="#sqlresultsetmapping">22.2.32. &#64;SqlResultSetMapping</a></li>
<li><a class="reference internal" href="#table">22.2.33. &#64;Table</a></li>
<li><a class="reference internal" href="#uniqueconstraint">22.2.34. &#64;UniqueConstraint</a></li>
<li><a class="reference internal" href="#version">22.2.35. &#64;Version</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="yaml-mapping.html"
                                  title="previous chapter">21. YAML Mapping</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="php-mapping.html"
                                  title="next chapter">23. PHP Mapping</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/reference/annotations-reference.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
        </div>
      </div>
          <div class="clearer"></div>
        </div>
          <div class="footer">
              &copy; Copyright 2010-12, Doctrine Project Team.
              Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
            <br/>
            <a target="_BLANK" href="http://www.servergrove.com"><img src="../_static/servergrove.jpg" /></a>      <br/><br/>
            <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
              <input type="hidden" name="cmd" value="_s-xclick" />
              <input type="hidden" name="hosted_button_id" value="BAE2E3XANQ77Y" />
              <input type="Submit" value="Donate via PayPal" />
            </form>
          </div>
      </div>

      <div id="bot-rcnr">
        <div class="tl"><!-- corner --></div>
      </div>
    </div>

  <a class="githublink" href="http://github.com/doctrine">Fork me on GitHub</a>
  </body>
</html>