I have 3 tables: movie, movie_category and category I create entities class
@Entity
@Table(name = "category")
@Data
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer categoryId;
private String name;
}
public class Movie {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer movieId;
........
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<MovieCategory> movieCategories;
}
@Entity
@Table(name="movie_category")
@Data
public class MovieCategory {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer movieCategoryId;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "movieId", referencedColumnName = "movieId")
private Movie movie;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "categoryId", referencedColumnName = "categoryId")
private Category category;
}
One movie has many film_categories. When i use JpaRepository interface and findAll() for Movie entity hiberante return movieCategories as empty array. I using bidirectional perspective. Using unidirectional is possible return Movie with list categories?