Home JPA or JPQL how to return single row from a many to many relationship
Reply: 0

JPA or JPQL how to return single row from a many to many relationship

user928
1#
user928 Published in May 25, 2018, 11:08 am

Learning JPA and JPQL. I have 3 database tables (as example): TVShow and Genre, and a Join table show_genre (having only show_id and genre_id) for the many-to-many relationship between tvShow and genre.

I have 2 annotated Java entities : Genre.java:

  @JsonManagedReference(value="showToGenre")
  @ManyToMany(mappedBy="genres", fetch=FetchType.EAGER)
  private Set<TVShow> tvShows;

and TVShow.java

@JsonBackReference(value="showToGenre")
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="show_genre",     
        joinColumns=@JoinColumn(name="show_id"),   
        inverseJoinColumns=@JoinColumn(name="genre_id")  
)
private Set<Genre> genres;

Is there a JPA or JPQL way to find a specific row in this Many to Many, like given a genre id, and a tvShow id, can I find the specific genre object for the given tvShow id?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.368623 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO