1

Id like to know if there's a way of doing something like the Stream API groupingBy Collector. I know hot to select one column (the question was marked as duplicated and I don't belive it is) I want to do a grouping (like the groupingBy collector of the java Stream API) not a group By. Suppose you have a table (ONE table) like:

+---+---+
+ A | B +
+---+---+
+ 1 | 1 +
+ 1 | 2 +
+ 1 | 3 +
+ 2 | 1 +
+---+---+

And I would like to have something like

@Entity
public class MyEntity {
  private int a;
  private List<Integer> b;
}

with a repo like

public interface MyCrudRepo extends CrudRepository<MyEntity,Integer>{
  List<MyEntity> findByA();
} 

or

public interface MyCrudRepo extends CrudRepository<MyEntity,Integer>{
  @Query("SSELECT m.a,m.b FROM MyEntity m")
  List<MyEntity> customFind();
} 

This is not necessarily how it should look at the end, anything that works similar to this is fine. I have looked into projections but all examples use 2 different tables.

Amakak
  • 31
  • 5
  • Seems like you are trying to query Join Table for Table A and Table B. This may help in that case : [how-to-query-the-join-table-using-hibernate](https://stackoverflow.com/questions/39848443/how-to-query-the-join-table-using-hibernate) – SkillsIndexOutOfBounds Aug 25 '20 at 01:48
  • There is a clarification at the end of the question that specificaly says Im trying to do this with ONE table. – Amakak Aug 25 '20 at 05:19

0 Answers0