@Entity
@Table(name="DMS_Document_Class")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "docClassindexID")
public class DMSDocumentClass {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="DocumentClass_Index_ID")
private long docClassindexID;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "DOCCLASS_GROUP",
joinColumns = {@JoinColumn(referencedColumnName ="DocumentClass_Index_ID")}, inverseJoinColumns = {@JoinColumn(referencedColumnName="groupID")})
@JsonManagedReference
private List<DMSGroupBean> groups;
@ManyToMany(mappedBy = "documentClass", fetch = FetchType.LAZY)
private List<DMSDocument> documents;
DMS文件类
public class DMSDocument {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="Doc_Index_ID")
private long docID;
@OneToOne
@JoinTable(name = "DOCCLASS_DOCS",
joinColumns = {@JoinColumn(referencedColumnName ="Doc_Index_ID")},
inverseJoinColumns = {@JoinColumn(referencedColumnName="DocumentClass_Index_ID")})
@JsonBackReference
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
private DMSDocumentClass documentClass;
下面是我尝试查询Annotation的存储库类。
@Query(value = "SELECT count(D.documents) from DMSDocumentClass D where D.docClassindexID = :classID")
public Long isDocClassHasDocument(@Param("classID") long classID);
当我试图执行这段代码的时候
docClassRepo.isDocClassHasDocument(docClassID);
我得到的输出如下
select
count(.) as col_0_0_
from
dms_document_class dmsdocumen0_ cross
join
docclass_docs documents1_, dms_document dmsdocumen2_
left outer join
docclass_docs dmsdocumen2_1_
on dmsdocumen2_.doc_index_id=dmsdocumen2_1_.doc_index_id
where
dmsdocumen0_.document_class_index_id=documents1_.document_class_document_class_index_id
and documents1_.doc_index_id=dmsdocumen2_.doc_index_id
and dmsdocumen0_.document_class_index_id=?
这里给出了count(.),导致SQL语法错误。我想获得特定文档类的文档数,但它在查询中写的是.。我应该传递什么来获取与文档类相关联的文档数。
你可以使用 size()
@Query(value = "SELECT size(D.documents) from DMSDocumentClass D where D.docClassindexID = :classID")
public int isDocClassHasDocument(@Param("classID") long classID);