E ai moçada…
Meu problema é simples, preciso recuperar uma lista de objeto que tenha um FK = ?
Entretanto preciso usar Criteria…
Estou fazendo assim:
Criteria criteria = session.createCriteria(CD.class);
Genre genre = getGenre(Integer.parseInt(form.getCbGenres()));
criteria = criteria.add(Restrictions.eq(IUtil.TABLE_CD_GENRE,genre));
list = criteria.list();
minhas classes (Tirei tds os Sets e construtores para ficar menor):
@Entity
public class CD implements Serializable{
private static final long serialVersionUID = -1737170960980903311L;
private Integer id;
private String title;
private String artiste;
private Integer launchYear;
private Genre genre;
private Double price;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getId() {
return id;
}
@Column(name = IUtil.TABLE_CD_TITLE)
public String getTitle() {
return title;
}
@Column(name = IUtil.TABLE_CD_ARTISTE)
public String getArtiste() {
return artiste;
}
@Column(name = IUtil.TABLE_CD_YEAR)
public Integer getLaunchYear() {
return launchYear;
}
@ManyToOne
@JoinColumn(name = IUtil.TABLE_CD_GENRE)
public Genre getGenre() {
return genre;
}
@Column(name = IUtil.TABLE_CD_PRICE)
public Double getPrice() {
return price;
}
}
@Entity
public class Genre implements Serializable {
private static final long serialVersionUID = -8270755449685855786L;
private Integer id;
private String description;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getId() {
return id;
}
@Column(name = "description")
public String getDescription() {
return description;
}
}