4

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?
Duncan
  • 59
  • 2
  • 10
  • 1
    Refer here: http://stackoverflow.com/questions/38509882/how-are-spring-data-repositories-actually-implemented – Vasu Oct 30 '16 at 15:07

2 Answers2

5

(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?

Community
  • 1
  • 1
Vasu
  • 21,832
  • 11
  • 51
  • 67
  • Thanks for the fast reply. If Spring Data does not provide inmemory database then how can I use it without external database? I mean I can run the mentioned project without any database and after saving objects throught jpa I can read them. How does it possible if there is no inmemory database? – Duncan Oct 30 '16 at 15:13
  • You can use Oracle or Mysql or any Relational or Nosql databases. I did not understand why Spring need to provide the database ? – Vasu Oct 30 '16 at 15:16
  • 1
    Yes, you are right. I found h2database dependency in the pom xml what i missed before. – Duncan Oct 30 '16 at 15:19
2

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.

nhthai
  • 198
  • 2
  • 10