'HOW JOIN two tables JPQL

How create a join pageable USING JPQL in Class Movie with MovieLanguage?

The Class Movie as a relationship 1 to 1 with MovieLanguage.

Movie:

Entity
@Table(name = "tb_movie")
public class Movie {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;
    private Double score;
    private Integer count;
    private String image;
    
    public Movie() {}

    public Movie(Long id, String title, Double score, Integer count, String image) {
        this.id = id;
        this.title = title;
        this.score = score;
        this.count = count;
        this.image = image;
    }

    @OneToOne(cascade = CascadeType.ALL, mappedBy = "movie")
    @JsonManagedReference
    MovieLanguage movieLanguage;
    
/* getter and setter */

}

MovieLanguage:

@Entity
@Table(name = "tb_movie_language")
public class MovieLanguage {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String titleBrazil;
    private String titleSpanish;
    
    
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "movie_id")
    @JsonBackReference
    private Movie movie;
    
    public MovieLanguage(){}

/* getter and setter */
}

Here is a JPQL example in MovieJoinRepository, but not working:

MovieJoinRepository:


public interface MovieJoinRepository extends JpaRepository<Movie, Long> {
    
    
    
    @Query("SELECT obj FROM Movie obj INNER JOIN obj.movie_language mm WHERE obj.id = mm.id ")
    Page<String> findAllPaged(Pageable pageable);
}

Thank you for you help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source