0

2 つの関連するテーブルに同時にデータを挿入しているときに、Doctrine 2 でこのエラーが発生します。

挿入のための私のコードは次のとおりです。

require_once("../test/doctrine/cli-config.php");
require_once "../test/doctrine/bootstrap.php";
require_once ("Users.php");
require_once ("ServiceProvider.php");



        $user = new Users();
        $user->setFirst_name('ABC');

        $serviceprovider = new ServiceProvider();
        $serviceprovider->setRib('111');
        // relate this user to the serviceprovider
        $user->setServiceProvider($serviceprovider);

        $em = $this->getDoctrine()->getManager();
        $em->persist($serviceprovider);
        $em->persist($user);
        $em->flush();

      return new Response(
            'Created User id: '.$user->getId_user().' and Service Provider id: '.$serviceprovider->getId()
        );

ユーザーエンティティ:

<?php

 /**
 * @Entity
 * @Table(name="users")
 * Total Number of Columns : 32
 */

class Users{

                         /**
                         * @OneToOne(targetEntity="ServiceProvider", mappedBy="users")
                         */
                            private $serviceprovider;


/* Attributes of Users */

     /** 
     * private long id_user
     * @Id 
     * @Column(type="integer") 
     * @GeneratedValue
     * @dummy
     * @Assert\NotEmpty
     */
       private $id_user;

     /** 
     * private Date dateSubscri 
     * @Column(type="string")
     */

     /** 
     * private String first_name 
     * @Column(type="string")
     * @Assert\NotEmpty
     */
       private $first_name;

/* Operations of Users */


       public function __construct()  
       {  
            echo 'The class "', __CLASS__, '" was initiated!<br />'; 
       } 


       /* public Users() */
       public function Users(){
        } 

       public function setServiceProvider($serviceprovider){
           $this->serviceprovider = $serviceprovider;
       }

       public function getServiceProvider(){
           return $this->serviceprovider;
       }

       public function getId_user(){
           return $this->id_user;
       }

       public function setId_user($user_id){ 
            $this->id_user=$user_id;
       }

       public function getFirst_name(){ 
           return $this->first_name;
       }
}
?>

サービス プロバイダー エンティティ:

<?php

 /**
 * @Entity
 * @Table(name="serviceprovider")
 */


class ServiceProvider{


     // ...

                 /**
                 * @OneToOne(targetEntity="Users", inversedBy="serviceprovider")
                 * @JoinColumn(name="fk_user_id", referencedColumnName="id_user")
                 */
                    private $users;



     // ...



/* Attributes of ServiceProvider */


     /** 
     * private long id  
     * @Id 
     * @Column(type="integer") 
     * @GeneratedValue
     */
       private $id;

     /** 
     * private long id  
     * @Column(type="integer") 
     */
       private $fk_user_id;




/* Operations of ServiceProvider */

       public function __construct()  
       {  
            echo 'The class "', __CLASS__, '" was initiated!<br />'; 
       } 

       /* public ServiceProvider getId() */
       public function getId(){
           return $this->id;
        } 

       /* public  getUser() */
       public function getUser(){
           return $this->fk_user_id; 
       }

       /* public void setUser(fk_user_id) */
       public function setUser($fk_user_id){ 
            $this->fk_user_id = $fk_user_id;
       }


}

?>

ここで何が間違っていますか?

4

1 に答える 1