我有下一个实体。Car
与 具有多对多关系Human
。我在Car和User之间使用辅助类Assign
@Entity
public class Car implements Serializable
{
//...
@LazyCollection(LazyCollectionOption.TRUE)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "car")
private Set<Assign> cars = new HashSet<Assign>();
//...
}
@Entity
class Assign implements Serializable
{
//...
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToOne
@JoinColumn(name = "HUMAN_CAR", nullable = false)
private Human human;
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToOne
@JoinColumn(name = "CAR_HUMAN", nullable = false)
private Car car;
//..
}
@Entity
public class Human implements Serializable
{
//...
@LazyCollection(LazyCollectionOption.TRUE)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "human")
private Set<Assign> cars = new HashSet<Assign>();
// ...
}
现在我尝试在容器管理事务中删除汽车
public void deleteCar(final long id)
{
final Car car = entityManager.find(roleId, Car.class);
entityManager.remove(car);
}
但我明白了
Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.dto.Assign#<null>]