2

I would like to ask if its possible to write Spring JPA method in repo avoiding SQL and @Query. This method have to return list which joined list value is equal to something.

This is class:

class Temp1{
 val a: String,
}

This is class that contains above class:

class Temp{
val aSet: Set<Temp1>
}

And so I would like to have method in repo that return every Temp which aSet "a" value is equal to string.

I've got now: findByaSetIn(aSet: List<Temp>) but it requires list of Temp values instead of more precisly "a" value.

In sql its something similar to:

SELECT * FROM Temp t JOIN Temp1 t1 ON t1.tempID = t.id WHERE t1.a = "abc"
MrNetroful
  • 497
  • 8
  • 28
  • Possible duplicate of [spring data - Mongodb - findBy Method for nested objects](https://stackoverflow.com/questions/12730370/spring-data-mongodb-findby-method-for-nested-objects) – snowe Mar 23 '18 at 21:43
  • refer to https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-property-expressions for how to query nested values – snowe Mar 23 '18 at 21:43

1 Answers1

3

What you're looking for is Containing.

In your example it should be like this:

findByASetContaining(item :Temp1)

The method will return a collection of all "Temp" entities where the "aSet" contains the entity "item".

You can use Containing not only for the search in lists and sets, it works also for the search in string values.

Christoph
  • 1,993
  • 1
  • 25
  • 33