我是教义的新手。我有一个带有注释的用户课程。主要键是$ userId,即字符串。我想手动设置ID,而不是自动设置$ USERID。我怎么不确定该怎么做?
<?php
namespace models;
/**
* User
*
* @Table(name="user")
* @Entity
*/
class User
{
/**
* @var string $userid
*
* @Column(name="userid", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $userid;
/**
* @var string $fullname
*
* @Column(name="fullname", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
private $fullname;
/**
* @var string $password
*
* @Column(name="password", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
private $password;
/**
* @var string $email
*
* @Column(name="email", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
private $email;
/**
* Get userid
*
* @return string $userid
*/
public function getUserid()
{
return $this->userid;
}
/**
* Set fullname
*
* @param string $fullname
*/
public function setFullname($fullname)
{
$this->fullname = $fullname;
}
/**
* Get fullname
*
* @return string $fullname
*/
public function getFullname()
{
return $this->fullname;
}
/**
* Set password
*
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get password
*
* @return string $password
*/
public function getPassword()
{
return $this->password;
}
/**
* Set email
*
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get email
*
* @return string $email
*/
public function getEmail()
{
return $this->email;
}
}
,如果我什至将ID公开并自己设置,则该学说2仍然插入默认值,即空字符串,导致违反完整性约束。有人可以为此提供详细的解决方案。
从@ID定义中删除@generatedValue线。您正在要求学说为您生成ID。