我想从Communication
表中获取appointment_type_ids
列表中包含Integer
的行。
Communication.java
@Getter
@Setter
@Entity
@Table(name = "communication")
public class Communication{
@Column("id")
private Long id;
@Column("name")
private String name;
@Column("appointment_type_ids")
private List<Integer> appointmentTypeIds;
}
CommunicationRepository.java
@Repository
public interface CommunicationRepository extends JpaRepository<Communication, Long>,
QuerydslPredicateExecutor<Communication>, JpaSpecificationExecutor<Communication> {
@Query("SELECT c FROM communication c WHERE ?1 = ANY(c.appointment_type_ids)")
List<Communication> findAppointments(Integer integer);
}
我得到以下错误
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: c near line 1, column 56 [SELECT c FROM communication c WHERE ?1 = ANY(c.appointment_type_ids)]
我该如何解决这个问题?
我认为你应该通过Communication
而不是communication
来引用表。所以应该是
SELECT c FROM Communication c WHERE ?1 = ANY(c.appointment_type_ids)
任何表达式都需要子查询,我认为您需要MEMBER OF来进行查询。
@Query("SELECT c FROM Communication c WHERE ?1 MEMBER OF c.appointentTypeIds")
你可以试试这个吗:
SELECT c FROM Communication c WHERE ?1 in(c.appointment_type_ids)