As I have read in the documentation, Spring Data JDBC supports query creation like Spring Data JPA
For Example:
findByProperty(Property property)
My question :
Does Spring Data JDBC support situation where we create a query and join two (or more) entities using their properties to find the result like in Spring Data JPA?
Example:
@Entity
class Person {
private final @Id Long id;
private final Car car;
}
@Entity
class Car {
private final @Id Long id;
private String color;
}
interface PersonRepository extends CrudRepository<Person, Long> {
List<Person> findByCarColor(Color red);
}
interface CarRepository extends CrudRepository<Car, Long> {
}
I want to find all persons who have at least one red car. Will that method gives proper output?
Spring Data JDBC has less abstractions than Spring Data JPA, but uses Spring Data concepts to make it easier to do CRUD operations than Spring JDBC. It sits closer to the database because it does not contain the most part of the Spring Data magic when querying the database.
Spring Boot provides a starter spring-boot-starter-jdbc for using JDBC with relational databases.
Spring Data JDBC aims at being conceptually easy. In order to achieve this it does NOT offer caching, lazy loading, write behind or many other features of JPA. This makes Spring Data JDBC a simple, limited, opinionated ORM.
JDBC is database-dependent, which means that different scripts must be written for different databases. On the other side, JPA is database-agnostic, meaning that the same code can be used in a variety of databases with few (or no) modifications.
I'm afraid you misread the documentation.
Query derivation is not supported in the 1.0 version of Spring Data JDBC. It certainly will be added in the not too far future.
The misunderstanding stems from the fact that all Spring Data documentation starts with a general part outlining the features in principle available to modules. This part is the same for all modules. And then the module specific part which describes the actual features. Unfortunately, the fact that Query Derivation is not supported can only be deducted from the fact it isn't mentioned in the module specific part.
Once this feature arrives it most likely will support querying across entities, but at least in the beginning only across entities of the same aggregate.
The concept of aggregates is extremely important for Spring Data JDBC, which is why there is a blog article about this concept and its ramifications for Spring Data JDBC, which I highly recommend for reading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With