Hibernate查询抛出java.util.ArrayList不能强制转换为类java.lang.Enum

u0sqgete  于 2023-03-23  发布在  Java
关注(0)|答案(1)|浏览(189)

此对存储库方法的查询

@Query(
    "SELECT a FROM AttachmentEntity a " +
        "WHERE (:projectId IS NULL OR a.projectId = :projectId) " +
        "AND (:attachmentTypes IS NULL OR a.attachmentType IN :attachmentTypes) " +
        "AND (:eventType IS NULL OR a.eventType = :eventType) ")
fun getAttachments(
    projectId: Int?,
    attachmentTypes: List<AttachmentType>?,
    eventType: EventType?
): List<AttachmentEntity>

调用时抛出此异常:

class java.util.ArrayList cannot be cast to class java.lang.Enum (java.util.ArrayList and java.lang.Enum are in module java.base of loader 'bootstrap')

当我删除:attachmentTypes IS NULL OR时,它工作了。
这可能是hibernate查询解析器中的一个bug吗?
我可以通过在方法内部构建查询来解决这个问题,但是有没有其他方法来解决这个问题呢?

相关问题