Spring Data JPA underlying mechanism without imple

2019-07-20 08:18发布

I started to read this tutorial: spring boot tutorial

In this I read that under model module they implemented POJOs and Repository interfaces. -> tutorial on github

In Repository interfaces I found two methods without implementations: findByUsername, findByAccountUsername.

My questions are:

  1. How does it work when those methods in repository interfaces have no implementations and those are not inherited from any super class?
  2. Does it work with name conventions and reflections?
  3. Does Spring Data has inmemory database to work with?

2条回答
混吃等死
2楼-- · 2019-07-20 09:01

For your question 1 and 2, they are right. They use naming convention and reflection. If you don't want to use their naming convention, you can use @Query with HQL, and certainly the hidden class (which implements for your interface) will handle these query also (you don't need to roll the implementation out).
For your last question, as list of IMDB here: https://en.wikipedia.org/wiki/List_of_in-memory_databases , spring data is not supporting for them. You must invoke another Java driver or spring product for each one.

查看更多
不美不萌又怎样
3楼-- · 2019-07-20 09:16

(1) How does it work when those methods in repository interfaces have no implementations and those are not inherited from any super class?

The Repository interfaces are being implemented (backed up) by Spring Container at Runtime.

(2) Does it work with name conventions and reflections?

Yes, it works on naming conventions and spring container uses JDK's proxy classes to intercept the calls to the Repository.

(3) Does Spring Data has inmemory database to work with?

No, Spring does not use any inmemory database

Please refer the below link for more detailed explanation:

How are Spring Data repositories actually implemented?

查看更多
登录 后发表回答