当前位置: 首页 > 知识库问答 >
问题:

HQL组织。冬眠QueryException:无法解析属性

刁钧
2023-03-14

我想写一个简单的不存在的地方子句HQL查询。我不熟悉Hibernate,我有一些小问题。

我的查询如下所示:

from Day as d 
where d.IDFest = 27 
and not exists (
  from tickets  t
  where t.IDUser = 1
  and t.IDFest = 27
) 

我想选择所有包含IDUser当天购买的门票的天数。所有这些都与id为IDFest的节日相关。

我的堆栈跟踪:

org.hibernate.QueryException: could not resolve property: IDFest of: entities.Day [from entities.Day as d  where d.IDFest = 27  and not exists (    from tickets  t     where t.IDUser = 1  and t.IDFest = 27 )  ]  
at org.hibernate.QueryException.generateQueryException(QueryException.java:137)     
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)    
at org.hibernate.hql.internal.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:247)     
at org.hibernate.hql.internal.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:209)     
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)    
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)     
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)   
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)     
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)     
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796) 
Caused by: org.hibernate.QueryException: could not resolve property: IDFest of: entities.Day    
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83)    
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77)   
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1978)     
at org.hibernate.hql.internal.classic.PathExpressionParser.getPropertyType(PathExpressionParser.java:291)   
at org.hibernate.hql.internal.classic.PathExpressionParser.end(PathExpressionParser.java:334)   
at org.hibernate.hql.internal.classic.WhereParser.doPathExpression(WhereParser.java:371)    
at org.hibernate.hql.internal.classic.WhereParser.doToken(WhereParser.java:404)     
at org.hibernate.hql.internal.classic.WhereParser.token(WhereParser.java:285)   
at org.hibernate.hql.internal.classic.ClauseParser.token(ClauseParser.java:107)     
at org.hibernate.hql.internal.classic.PreprocessingParser.token(PreprocessingParser.java:131)   
at org.hibernate.hql.internal.classic.ParserHelper.parse(ParserHelper.java:61)  
at org.hibernate.hql.internal.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:239)     ... 9 more

映射类:

Day.java

package entities;
// Generated Feb 17, 2017 1:18:27 AM by Hibernate Tools 4.3.1

/**
*   Day generated by hbm2java
*/
@Entity
@Table(name = "day", catalog = "pia"
)
public class Day implements java.io.Serializable {

private Integer idday;
private Festivals festivals;
private Date date;
private int totalTickets;
private int leftTickets;

public Day() {
}

@Id
@GeneratedValue(strategy = IDENTITY)

@Column(name = "IDDay", unique = true, nullable = false)
public Integer getIdday() {
    return this.idday;
}

public void setIdday(Integer idday) {
    this.idday = idday;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "IDFest", nullable = false)
public Festivals getFestivals() {
    return this.festivals;
}

public void setFestivals(Festivals festivals) {
    this.festivals = festivals;
}

@Temporal(TemporalType.DATE)
@Column(name = "date", nullable = false, length = 10)
public Date getDate() {
    return this.date;
}

public void setDate(Date date) {
    this.date = date;
}

@Column(name = "totalTickets", nullable = false)
public int getTotalTickets() {
    return this.totalTickets;
}

public void setTotalTickets(int totalTickets) {
    this.totalTickets = totalTickets;
}

@Column(name = "leftTickets", nullable = false)
public int getLeftTickets() {
    return this.leftTickets;
}

public void setLeftTickets(int leftTickets) {
    this.leftTickets = leftTickets;
}

}

Festivals.java

package entities;
// Generated Feb 17, 2017 1:18:27 AM by Hibernate Tools 4.3.1

/**
 * Festivals generated by hbm2java
*/
@Entity
@Table(name = "festivals", catalog = "pia"
)
public class Festivals implements java.io.Serializable {

private Integer idfest;
private String name;
private String place;
private Date begin;
private Date end;
private int priceDay;
private int priceFestival;
private String facebook;
private String twitter;
private String instagram;
private String youtube;
private long visited;
private int ticketsPerUser;
private int ticketsPerDay;
private int totalRating;
private int numberRatings;
private Set<Users> userses = new HashSet<Users>(0);
private Set<Messages> messageses = new HashSet<Messages>(0);
private Set<Files> fileses = new HashSet<Files>(0);
private Set<Day> days = new HashSet<Day>(0);
private Set<Performers> performerses = new HashSet<Performers>(0);
private Set<Tickets> ticketses = new HashSet<Tickets>(0);
private Set<Comments> commentses = new HashSet<Comments>(0);

public Festivals() {
}

@Id
@GeneratedValue(strategy = IDENTITY)

@Column(name = "IDFest", unique = true, nullable = false)
public Integer getIdfest() {
    return this.idfest;
}

public void setIdfest(Integer idfest) {
    this.idfest = idfest;
}

@Column(name = "name", nullable = false, length = 45)
public String getName() {
    return this.name;
}

public void setName(String name) {
    this.name = name;
}

@Column(name = "place", nullable = false, length = 45)
public String getPlace() {
    return this.place;
}

public void setPlace(String place) {
    this.place = place;
}

@Temporal(TemporalType.DATE)
@Column(name = "begin", nullable = false, length = 10)
public Date getBegin() {
    return this.begin;
}

public void setBegin(Date begin) {
    this.begin = begin;
}

@Temporal(TemporalType.DATE)
@Column(name = "end", nullable = false, length = 10)
public Date getEnd() {
    return this.end;
}

public void setEnd(Date end) {
    this.end = end;
}

@Column(name = "priceDay", nullable = false)
public int getPriceDay() {
    return this.priceDay;
}

public void setPriceDay(int priceDay) {
    this.priceDay = priceDay;
}

@Column(name = "priceFestival", nullable = false)
public int getPriceFestival() {
    return this.priceFestival;
}

public void setPriceFestival(int priceFestival) {
    this.priceFestival = priceFestival;
}

@Column(name = "facebook", length = 100)
public String getFacebook() {
    return this.facebook;
}

public void setFacebook(String facebook) {
    this.facebook = facebook;
}

@Column(name = "twitter", length = 100)
public String getTwitter() {
    return this.twitter;
}

public void setTwitter(String twitter) {
    this.twitter = twitter;
}

@Column(name = "instagram", length = 100)
public String getInstagram() {
    return this.instagram;
}

public void setInstagram(String instagram) {
    this.instagram = instagram;
}

@Column(name = "youtube", length = 100)
public String getYoutube() {
    return this.youtube;
}

public void setYoutube(String youtube) {
    this.youtube = youtube;
}

@Column(name = "visited", nullable = false)
public long getVisited() {
    return this.visited;
}

public void setVisited(long visited) {
    this.visited = visited;
}

@Column(name = "ticketsPerUser", nullable = false)
public int getTicketsPerUser() {
    return this.ticketsPerUser;
}

public void setTicketsPerUser(int ticketsPerUser) {
    this.ticketsPerUser = ticketsPerUser;
}

@Column(name = "ticketsPerDay", nullable = false)
public int getTicketsPerDay() {
    return this.ticketsPerDay;
}

public void setTicketsPerDay(int ticketsPerDay) {
    this.ticketsPerDay = ticketsPerDay;
}

@Column(name = "totalRating", nullable = false)
public int getTotalRating() {
    return this.totalRating;
}

public void setTotalRating(int totalRating) {
    this.totalRating = totalRating;
}

@Column(name = "numberRatings", nullable = false)
public int getNumberRatings() {
    return this.numberRatings;
}

public void setNumberRatings(int numberRatings) {
    this.numberRatings = numberRatings;
}

@ManyToMany(fetch = FetchType.EAGER, mappedBy = "festivalses")
public Set<Users> getUserses() {
    return this.userses;
}

public void setUserses(Set<Users> userses) {
    this.userses = userses;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "festivals")
public Set<Messages> getMessageses() {
    return this.messageses;
}

public void setMessageses(Set<Messages> messageses) {
    this.messageses = messageses;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "festivals")
public Set<Files> getFileses() {
    return this.fileses;
}

public void setFileses(Set<Files> fileses) {
    this.fileses = fileses;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "festivals")
public Set<Day> getDays() {
    return this.days;
}

public void setDays(Set<Day> days) {
    this.days = days;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "festivals")
public Set<Performers> getPerformerses() {
    return this.performerses;
}

public void setPerformerses(Set<Performers> performerses) {
    this.performerses = performerses;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "festivals")
public Set<Tickets> getTicketses() {
    return this.ticketses;
}

public void setTicketses(Set<Tickets> ticketses) {
    this.ticketses = ticketses;
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "festivals")
public Set<Comments> getCommentses() {
    return this.commentses;
}

public void setCommentses(Set<Comments> commentses) {
    this.commentses = commentses;
}

}

门票。Java语言

package entities;
// Generated Feb 17, 2017 1:18:27 AM by Hibernate Tools 4.3.1

/**
* Tickets generated by hbm2java
*/
@Entity
@Table(name = "tickets", catalog = "pia"
)
public class Tickets implements java.io.Serializable {

private Integer idtic;
private Festivals festivals;
private Users users;
private int isBought;
private int price;
private Date date;

public Tickets() {
}

@Id
@GeneratedValue(strategy = IDENTITY)

@Column(name = "IDTic", unique = true, nullable = false)
public Integer getIdtic() {
    return this.idtic;
}

public void setIdtic(Integer idtic) {
    this.idtic = idtic;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "IDFest", nullable = false)
public Festivals getFestivals() {
    return this.festivals;
}

public void setFestivals(Festivals festivals) {
    this.festivals = festivals;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "IDUser", nullable = false)
public Users getUsers() {
    return this.users;
}

public void setUsers(Users users) {
    this.users = users;
}

@Column(name = "isBought", nullable = false)
public int getIsBought() {
    return this.isBought;
}

public void setIsBought(int isBought) {
    this.isBought = isBought;
}

@Column(name = "price", nullable = false)
public int getPrice() {
    return this.price;
}

public void setPrice(int price) {
    this.price = price;
}

@Temporal(TemporalType.DATE)
@Column(name = "date", nullable = false, length = 10)
public Date getDate() {
    return this.date;
}

public void setDate(Date date) {
    this.date = date;
}

}

共有1个答案

夏侯兴怀
2023-03-14

您应该在查询中使用hql(而不是sql),如

where d.festivals.id = 27
 类似资料:
  • 我正在尝试从当前用户那里获取特定租金的列表。 控制器中的代码: account\u id是外键。 运行后,我发现错误: 我做错了什么?

  • 我得到这个错误的原因很奇怪。我将解释这个错误是按时间顺序排列的,以便更容易理解。 这是我的JPA查询,在我添加po之前,它一直工作得很好。it的customer\u id。 商店订单构造器 错误: 我很困惑为什么我调用的表中的一列不被识别。我已经玩了一段时间了,但感觉就像在追我的尾巴。 -------更新------- 我注意到表中的其他BigInt变量在构造函数中很长。因此,我将customer

  • 我需要你帮我把冬眠映射成一对多我不知道为什么这是错的 另一类: 映射 另一个映射: Hibernate配置 这就是错误: 如果有人能帮我,我非常感激,谢谢!

  • 有人知道为什么我会得到这个错误吗: @entity@table(name=“salidas_procesionales”,catalog=“sahe”)公共类SalidasProcesionales实现java.io.serializable{ 我已经删除了长度的构造函数。

  • 我已经为这个问题挣扎了一段时间了。我有一个使用Struts2、spring和Hibernate的基于web的应用程序。我使用Spring将struts动作、业务和dao层连接在一起。我正在使用JMeter对应用程序进行负载测试。当我模拟1个用户反复发送get请求时,应用程序运行良好,没有问题。但是,当我再添加几个用户时,过了一段时间后,我得到以下错误: 所以,我假设这是一个连接泄漏,但是当我模拟一

  • 我有错误在我的Hibernate代码和我需要知道如何修复它 错误: “errorMessage:“无法初始化代理[tech.basarsoft.hayez.io.entity.University#gx8qcpipfnysrlripzmtgrt1qifuyb8]-无会话”, CollageEntryPOint类 拼贴: 和DAOSQL实现 这是hibernate。cfg文件 拼贴服务: 拼贴映射: