I'm trying to get a partial object back using projection in hibernate, like this:
Movie class:
@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;
When the user then goes to htp://localhost:8080/api/movies?fields=genres this is called:
Movie DAO:
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();
But this returns:
java.lang.ArrayIndexOutOfBoundsException: 0
org.hibernate.loader.criteria.CriteriaLoader.getResultRow(CriteriaLoader.java:166)
Hibernate Query:
select this_.id as y0_ from Movies this_
Projections do not work when you want to project a collection...
Can somebody tell me what to do? How can this be fixed?
Thanks in advance!