Tag: 多对一

Doctrine 2 – 在ManyToOne关系的外键上不允许空值

在我的一个实体中有一个ManyToOne关系,如下所示: class License { // … /** * Customer who owns the license * * @var \ISE\LicenseManagerBundle\Entity\Customer * @ORM\ManyToOne(targetEntity="Customer", inversedBy="licenses") * @ORM\JoinColumn(name="customer_id", referencedColumnName="id") */ private $customer; // … } class Customer { // … /** * Licenses that were at one point generated for the customer * * @var \Doctrine\Common\Collections\ArrayCollection * @ORM\OneToMany(targetEntity="License", mappedBy="customer") */ private […]

JPA:单向多对一和级联删除

说我有一个单向的 @ManyToOne关系如下: @Entity public class Parent implements Serializable { @Id @GeneratedValue private long id; } @Entity public class Child implements Serializable { @Id @GeneratedValue private long id; @ManyToOne @JoinColumn private Parent parent; } 如果我有一个父P和子C 1 … C n引用回P,那么在JPA中有一个干净漂亮的方法来在P被移除时自动删除子C 1 … C n (即entityManager.remove(P) )? 我在找的是一个类似于SQL中的ON DELETE CASCADE的function。