-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed as not planned
Closed as not planned
Copy link
Labels
for: external-projectFor an external project and not something we can fixFor an external project and not something we can fix
Description
Originally asked at: https://stackoverflow.com/questions/79740056/jpa-repository-method-with-native-query-containing-works-with-long-but-no
In one of my Spring Data JPA repositories I have this native query (PostgreSQL):
@Query(value = "SELECT * FROM ballots b WHERE b.companies && :companyIds and b.meeting_id in :meetingIds", nativeQuery = true)
List<Ballot> findByIds(Long[] companyIds, Long[] meetingIds);
Here's my entity:
@Table(name="ballots")
public class Ballot {
@Id
private long id;
@Column
private long meetingId;
@Type(ListArrayType.class)
@Column(name = "companies",columnDefinition = "bigint[]")
private List<Long> companies = new ArrayList<>();
}
Here's how I call the method:
private final BallotRepository ballotRepo;
public void findBallots(Set<Long> companyIds, Set<Long> companyMeetingIds) {
List<Ballot> ballots = ballotRepository.findByIds(companyIds, companyMeetingIds);
// the rest of the code
}
}
Repository method signature with
Long[] companyIds, Long[] meetingIds
works fineLong[] companyIds, Collection<Long> meetingIds
works fineCollection<Long> companyIds, Collection<Long> meetingIds
fails:
org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL [SELECT * FROM ballots b WHERE b.companies && (?) and b.meeting_id in (?,?)] [ERROR: operator does not exist: bigint[] && bigint
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
Position: 42] [n/a]; SQL [n/a]
I wonder why the framework successfully converts Long[]
into bigint[]
but fails when in comes to Collection<Long>
Metadata
Metadata
Assignees
Labels
for: external-projectFor an external project and not something we can fixFor an external project and not something we can fix