hibernate - Spring Data JPA repository query builder, many to many relationship -


i want construct find query in repository interface select elements mapped many many relationship.

user.java:

@entity @table(name = "user") public class user {     @id     @column(name = "id", columndefinition = "binary(16)")     private uuid id;      @column(name = "username")     private string username;      @column(name = "email")     private string email;      @column(name = "passwordhash")     private string passwordhash;      @manytomany(mappedby = "userstracking")     private set<show> shows; ... 

show.java:

@entity @table(name = "shows") public class show {      @id     @column(name = "id", columndefinition = "binary(16)")     private uuid id;      @column(name = "imdb_id", length = 9, nullable = false)     private string imdbid;      @column(name = "title", length = 100, nullable = false)     private string title;      @column(name = "poster_url", length = 255, nullable = true)     private string posterurl;      @column(name = "rating", length = 3, nullable = true)     private double rating;      @column(name = "genre", length = 100, nullable = true)     private string genre;      @manytomany     @jointable(name = "users_shows",             joincolumns = @joincolumn(name = "show_id", referencedcolumnname = "id"),             inversejoincolumns = @joincolumn(name = "user_id", referencedcolumnname = "id"))     private set<user> userstracking; ... 

to achieve using query builder (i think it's called) have written repository:

public interface showrepository extends crudrepository<show, uuid> {     list<show> findbyuser(user user); } 

but able shows userrepository rather showrepository, should write this?

public interface userrepository extends crudrepository<user, uuid> {     list<show> findshows();     //or maybe?     list<show> findshowsbyuser(user user); } 

am understanding whole query building correctly?


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -