Hibernate使用交叉连接删除查询

时间:2017-04-17 10:49:06

标签: hibernate spring-data-jpa

我正在尝试执行删除查询,如下所示:

@Modifying
@Query("delete from Document d where d.requestDocument.request.id = :requestId and d.documentType.lookupCode in (:documentTypeLookupCodes)")
Integer deleteByRequestIdAndDocumentTypes(@Param("requestId") Long requestId, @Param("documentTypeLookupCodes") List<String> documentTypeLookupCodes);

我正在使用spring数据jpa存储库,当它执行时会生成:

DELETE FROM sakreg_documents cross join request_docs requestdoc1_ cross join sakreg_doc_type documentty2_ where sakreg_request_id=1111 and (lkp_code in ('IN' , 'OUT'))

并抛出

  

ORA-00933:SQL命令未正确结束

文件实体:

@Entity
@Table(name = "SAKREG_DOCUMENTS")
public class Document {
      @Id
      @SequenceGenerator(name = "DocumentSequence", sequenceName = "SAKREG_DOCUMENTS_SEQ", allocationSize = 1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DocumentSequence")
      @Column(name = "ID")
      private Long id;

      @OneToOne(mappedBy="document", fetch = FetchType.LAZY)
      private RequestDocument requestDocument;

      @ManyToOne
      @JoinColumn(name = "SAKREG_DOC_TYPE_ID_FK")
      private DocumentType documentType;
}

RequestDocument实体:

@Entity
@Table(name = "REQUEST_DOCS")
public class RequestDocument {
      @Id
      @SequenceGenerator(name = "requestDocSequence", sequenceName = "REQUEST_DOCS_SEQ", allocationSize = 1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "requestDocSequence")
      @Column(name = "ID")
      private Long id;

      @ManyToOne
      @JoinColumn(name="SAKREG_REQUEST_ID")
      private Request request;

      @OneToOne
      @JoinColumn(name="SAKREG_DOC_ID")
      private Document document;
}

请求实体:

    @Entity
    @Table(name = "SAKREG_REQUEST")
    public class Request {
          @Id
          @SequenceGenerator(name = "requestIdSequence", sequenceName = "SAKREG_REQUEST_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "requestIdSequence")
    @Column(name = "ID")
    @CmProperty(symbolicName = "RequestId")
    private Long id;
}

DocumentType实体:

@Entity
@Table(name = "SAKREG_DOC_TYPE")
public class DocumentType{
@Id
    @GeneratedValue
    @Column(name = "ID")
    private Short id;
}

那么,我如何编写一个可以删除文档的删除语句 使用具有特定请求标识的RequestDocument

0 个答案:

没有答案