我知道truncate
不受支持,因此我执行了Delete from table
- 这项工作非常好但是连接表不会以这种方式清理。例如:
Delete from Product;
Delete from Service;
两个空,表service_product
仍然填充。有没有机会在没有原始sql的情况下清理我的连接表?
示例实体
public class Service implements Serializable {
private static final long serialVersionUID = 4520872456865907866L;
// seam-gen attributes (you should probably edit these)
@EmbeddedId
private ServiceId id;
@Length(max = 255)
private String servicename;
@Column(columnDefinition = "text")
private String highlightsText;
@Column(columnDefinition = "text")
private String detailsText;
@Column(columnDefinition = "text")
private String productText;
@Column(columnDefinition = "text")
private String dataText;
@ManyToMany(mappedBy = "services")
private Set<Machine> machines;
@OneToMany(targetEntity = ServiceDownload.class, cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private List<ServiceDownload> serviceDownloads;
@OneToMany(targetEntity = ProductSpecial.class, cascade = { CascadeType.ALL })
private List<ProductSpecial> productSpecials;
@OneToOne(cascade = { CascadeType.ALL })
private ServicePicture servicePicture;
...
}
答案 0 :(得分:0)
FROM Product
),迭代实体并使用session.delete(..)
DELETE
不会触发级联truncate
答案 1 :(得分:0)
您应该添加@OnDelete(action = OnDeleteAction.CASCADE)注释。所以,如果您正在使用Hibernate,请尝试:
@OneToMany(targetEntity = ServiceDownload.class, cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@OnDelete(action=OnDeleteAction.CASCADE)
private List<ServiceDownload> serviceDownloads;
有关示例和文档,请参阅http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html。