'Is there a way to return user rating of a one book for that user?

I am working on a project, trying to create an AudioBook website. I am stuck on this part and i cant find answers on the internet.

The problem is when i get user, and list of favorite books, each book has list of user rating, from all of the users. And also there is a list of UserRatings that contains all of ratings from that user. I dont want neither.

Basically, is there a way to make it so when i do a search for list of books, every book object contains UserRating(One user rating) from a specific User that is logged in?

@Entity
@Table(name = "user_rating")
public class user_rating {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column
    private Integer Id;

    @Column
    private String rating;

    @ManyToOne
    @JoinColumn(name = "user_id")
    private users user;


    @ManyToOne
    @JoinColumn(name = "book_id")
    private books book;
@Entity
@Table(name = "users")
public class users {

    @Id
    @Column
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column
    private String name;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "email")
    private String email;

    @Column(name = "date_of_creation")
    private java.sql.Date dateOfCreation;

    @Column
    private String password;


    @JsonManagedReference
    @ManyToMany
    @JoinTable(
            name = "favourites",
            joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "book_id", referencedColumnName = "id")
    )
    private Set<books> favourites = new HashSet<>();

    @OneToMany(mappedBy ="user")
    private List<user_rating> UserRating = new ArrayList<>();
@Entity
@Table(name = "books")
public class books {

    @Id
    @Column
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column
    private String name;

    @Column
    private String description;

    @Column(name = "date_of_creation")
    private java.sql.Date date_of_creation;

    @Column
    private String text_file;

    @JsonBackReference
    @ManyToMany(mappedBy = "favourites")
    private Set<users> users = new HashSet<>();

    @JsonManagedReference
    @ManyToMany()
    @JoinTable(
            name = "book_tags",
            joinColumns = @JoinColumn(name = "book_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id")
    )
    private List<tags> tags = new ArrayList<>();

    @OneToOne
    @PrimaryKeyJoinColumn
    private audio_file audioFile;

    @OneToMany(mappedBy = "book")
    private List<user_rating> UserRatings = new ArrayList<>();


Sources

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

Source: Stack Overflow

Solution Source