我正在尝试使用休眠中的投影来取回部分对象,如下所示:
电影类:
@Table(name = "Movies")
public class Movie extends Entity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "title")
private String title;
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinTable(name = "Movie_Genre", joinColumns = {@JoinColumn(name = "movieId")}, inverseJoinColumns = {@JoinColumn(name = "genreId")})
private List<Genre> genres;
当用户然后转到 htp://localhost:8080/api/movies?fields=genres 这被称为:
电影道:
Criteria cr = getCurrentSession().createCriteria(Movie.class);
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("genres"), "genres");
cr.setProjection(projectionList);
cr.setResultTransformer(Transformers.aliasToBean(Movie.class));
return cr.list();
但这会返回:
java.lang.ArrayIndexOutOfBoundsException: 0
org.hibernate.loader.criteria.CriteriaLoader.getResultRow(CriteriaLoader.java:166)
休眠查询:
select this_.id as y0_ from Movies this_
当您想要投影集合时,投影不起作用...
有人可以告诉我该怎么做吗?如何解决这个问题?
提前致谢!