gpt4 book ai didi

java - HQL - 比较日期和对象

转载 作者:行者123 更新时间:2023-11-30 01:07:38 25 4
gpt4 key购买 nike

所以我有以下代码:

    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);

由于某种原因,此查询永远不会返回任何结果,artist 是 Artist 类的对象,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;
}
}

我的模型没有任何问题,我已将一些名称更改为英文版本,因此如果您认为模型中有错误,我可能只是忘记翻译它。

最佳答案

我修好了!我忘了 12 月是 Java 的第 11 个月,而不是第 12 个月...:(

关于java - HQL - 比较日期和对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19632936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com