JPQL中如何使用包含

时间:2018-10-03 10:09:23

标签: java jpql contains

我正在尝试将以下LinQ查询转换为JPQL。我不知道如何在jpql中使用contains。我尝试如下所示,但出现错误

LinQ查询语法

var Rooms = from rooms in EspaceDB.Rooms
                            where roomIDList.Contains(rooms.nRoomID.ToString())
                            select rooms;

JPQL查询语法

我尝试:

@Query("select room from Room as room where roomIDList.contains(room.nRoomId.ToString())")
    List<Room> recoverDeletedRoom(@Param(value = "roomIDList") String[] roomIDList);

并且:

@Query("select room from Room as room where contains(room.nRoomId,roomIDList)")
  List<Room> recoverDeletedRoom(@Param(value = "roomIDList") String[] roomIDList);

错误:

  

antlr.NoViableAltException:意外的AST节点:

1 个答案:

答案 0 :(得分:0)

这应该对您有用:

@Query("select room from Room room where room.id IN (:roomIDList)")
List<Room> recoverDeletedRoom( @Param("roomIDList") List<String> roomIDList);