I am trying to really understand how those Interfaces in Java work. As I know, it's kinda used to describe what implementing classes will do but not how to do that. That's clear enough for me.
The problem is, when I try to use CrudRepository interface from Spring Data package, then I don't really know how it works.
I create for example CarRepository which extends CrudRepository interface without adding any new methods.
After this I create CarService class which injects CarRepository via CarService constructor for dependency Injection.
Regarding to that I use save method from CarRepository and I am totally lost because I don't know, how it's possible that it's really saving the passed object to the database. The reason is, that this save method has no 'body', so that how does it know, how to insert to to the database?
The example of the code:
class CarService{
private CarRepository carRepository;
public CarService(CarRepository carRepository){
this.carRepository = carRepository;}
public Car saveCar(Car car){
Car savedCar = carRepository.save(car);
return savedCar;
}
}
}
Can you guys please clarify me, how is that possible that this method saves the car object to the any database configured to the spring? Cuz there is no body of save method, so how does it know how to do that?
spring.dataCGLib$somethingorJavassist$something, indicating that they were dynamically created via either CGLib or Javassist.