所以我有以下代码:
Query query = session.createQuery("select p.festivalDay from Performance p where p.startingTimestamp < :startingTimestamp " +
"and p.endingTimestamp> :endingTimestamp" +
"and p.artist= :artist");
query.setTimestamp("beginningTimestamp", cal.getTime());
cal.set(endHour, endMonth, endDay, endHour, endMinute);
query.setTimestamp("endingTimestamp", cal.getTime());
query.setParameter("artist", a);
由于某种原因,此查询永远不会返回任何结果,艺术家是类艺术家的对象,festivalDay是FestivalDay之一。
时间戳比较和艺术家比较似乎都失败了(我只用时间戳尝试了查询,我只用艺术家尝试过)。 (“a”显然是一个Artist对象)
这是我的表现模型:
@Entity
@Table(name = "T_Performance")
public class Performance{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private Date startingTimestamp;
private Date endingTimestamp;
private Date soundCheckUur;
@ManyToOne
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "podiumId")
private Podium podium;
@ManyToOne
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "artistId", nullable = false)
private Artist artist;
@ManyToOne
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "festivalDayId", nullable = false)
private FestivalDay festivalDay;
public Optreden(){
}
public Optreden(Date startingTimestamp, Date endingTimestamp, Date soundCheckHour) {
this.startingTimestamp = startingTimestamp;
this.endingTimestamp = endingTimestamp;
this.soundCheckHour = soundCheckHour;
}
public void setPodium(Podium podium) {
this.podium = podium;
}
public void setArtist(Artist artist) {
this.artist = artist;
}
public void setFestivalDay(FestivalDay festivalDay) {
this.festivalDay = festivalDay;
}
}
我的模型没有任何问题,我已将某些名称更改为英文版本,所以如果您认为您在模型中发现错误,我可能只是忘记翻译它。
答案 0 :(得分:0)
我修好了!我忘了12月是Java的第11个月,而不是12月...... :(