R. Pereira
R. Pereira

Reputation: 265

Using Spring JPA Select DISTINCT

I am having problems using spring jpa using a Distinct. My goal it's to return the whole object, instead just the field that pass to "Distinct".

Example: This is my table: enter image description here

And I want to Distinct the "Test_ID" where FLOW_ID = 345 So I am doing this:

Page findTestIdDistinctByFlowId(Pageable pageable, String FlowID);

enter image description here

Instead of this (my goal):

enter image description here

Any advice? Another option?

Upvotes: 0

Views: 154

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81988

Distinct doesn't apply on a column or select expression it operates on a row in SQL or an entity in JPA.

Since the returned IDs differ the rows are not distinct and get all returned.

I suspect you could achieve what you want with an explicitly written SQL or JPQL statement. But I'm not at all clear what the actual criteria is that you want to use.

Upvotes: 1

Related Questions