How to select query filter in one-to-one relationship with Spring Data JDBC ?
Schema looks like this, basically 2 tables where Rental references Movie
drop table if exists rental;
drop table if exists movie;
create table movie
(
id serial primary key,
title text,
description text
);
create table rental
(
movie integer primary key references movie (id),
duration text,
price integer
)
And my code looks like this
@Query("select * from movie where title = :title ")
fun findByTitle(@Param("title") title: String): List<Movie>
But got an exception org.springframework.data.mapping.MappingException: Could not read value rental_movie from result set!
The example project on GitHub.
P.S I am quite new to this and followed this video to learn basics, please help me to do it in proper way
Solution # 1
Use the @Query like this, but still not so good since there can be a lot of columns inside second table
SELECT movie.*,
rental.price AS rental_price,
rental.duration AS rental_duration,
rental.movie AS rental_movie
FROM movie
LEFT OUTER JOIN rental ON rental.movie = movie.id
where movie.title = 'Matrix'