Languages
[Edit]
EN

Spring JPA - using entity field names in @Query annotation

4 points
Created by:
RomanaLittle
458

In this post I would like to share that we can use entity field names in @Query annotations when we build new SQL query. Intellij IDEA will help us with intellicence. Entity needs to have getters.

Intellij IDEA intellicence hints with UserEntity field names

Repository:

Entity:

Unit test

We can test if it works, download this project and copy repository method + query and run below unit test:

Unit test result

TODO: make repo on github with this exampe based on repo:

References:

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java Persistence API (JPA)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join