0

I have many entities. Some of them have many attributes.

I found a way to generate repository for each entity, but is there a way to generate search methods (like findAllByLastname) inside a repository for each attribute of an entity, or some attributes that I want.

That will save me a lot of time.

For example I have entity with 20 attributes and need to search that entity by all it's attributes.

st.
  • 87
  • 4
  • You cannot have them auto generated, but should be able to write custom methods by implementing the interface JpaRepository – wonderlearner May 27 '18 at 08:20
  • @wonderlearner My repositories implements that interface and I’m able to write custom methods, but I want to speed up this process and generate them for each attribute of an entity. Are you sure there is no code generator for that? – st. May 27 '18 at 08:24
  • Check if you can find any useful APIs from Project Lombok that works for your use case. https://projectlombok.org/ – wonderlearner May 27 '18 at 08:28
  • @wonderlearner Lombok can not help here... – Dirk Deyne May 27 '18 at 08:41
  • 1
    If you find the way to query your data dynamically then you don't need to create 'search' methods for all repos, just use Querydsl and Web support Spring Data extensions with Spring Data REST and all will work right from the box: https://stackoverflow.com/a/48596145/5380322 – Cepr0 May 27 '18 at 10:04
  • @Cepr0 is correct Querydsl is your best option. And you are using `spring-data-rest` so the only thing you need to do is some extra configuration. Have a look here https://github.com/dirkdeyne/rest-data-querydsl – Dirk Deyne May 27 '18 at 12:16

0 Answers0