2

我想删除具有相同 ExternalProcessedFileInfo 的 ExternalProcessed 文件但此查询失败。当 Relation 恢复为 @onetomany 并在删除时级联时很容易,但我没有找到 ManytoOne 关系的任何有用示例。

这是我要运行的代码,它将为选择查询运行。

javax.persistence.Query query =this. manager.createQuery("Delete  from  ExternalProcessedFile "
                + " f WHERE f.processInfo.source.name= :source ");
          query.setParameter("source",source.getName()) ;
          EntityTransaction tran=  manager.getTransaction();
          try{
           tran.begin();
          query.executeUpdate();
          tran.commit();    

@Entity
@Table(name = "ProcessedFile")

public class ExternalProcessedFile implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "EID")
    private Long id;


     @NotNull
     @ManyToOne
     private  ExternalProcessedFileInfo processInfo;  

@Entity
@Table(name = "ProcessedFileInfo")
public class ExternalProcessedFileInfo implements Serializable {

    public ExternalProcessedFileInfo(){

    }
     public ExternalProcessedFileInfo(String processtime,ExternalDataStorage source){
        this.processTime=processtime;
        this.source=source;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "EID")
    private Long id;


    @ManyToOne
    @JoinColumn
    private ExternalDataStorage  source;


    @NotEmpty
    @Column(name = "processtime")
    private String processTime;
4

1 回答 1

1

DELETE 查询不考虑级联。您将必须获取每个实体及其entityManager.remove(..)

于 2011-06-07T14:24:31.410 回答