Hibernate HQL 用于按参数和标准查找
我很难理解 Hibernate HQL,只习惯于 sql,我不明白我的 HQL 有什么问题。任何帮助将不胜感激:
@Entity
public class KursKode {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String kursKode;
private boolean used;
@ManyToOne
@JoinColumn (name = "kursId")
@LazyCollection(LazyCollectionOption.FALSE)
private Kurs kurs;
....
}
我试图仅获取特定 Kurs 的“KursKode”。并且只有“KursKodes”具有“used = false”。所以我在我的 DAO 中尝试了这个:
List<KursKode> kursKodeList = getHibernateTemplate().find("from KursKode k where k.kurs.kursId = ? and not k.used", kursId);
但这给了我以下错误: 数据访问失败
意外 AST 节点: 。靠近第 1 行第 74 列 [来自 no.dahlsdata.model.Kurs.KursKode k,其中 k.kurs.kursId = ?而不是 k.used];嵌套异常是 org.hibernate.hql.ast.QuerySyntaxException: 意外的 AST 节点: 。靠近第 1 行第 74 列 [来自 no.dahlsdata.model.Kurs.KursKode k,其中 k.kurs.kursId = ?而不是 k.used]
Im struggeling to understand Hibernate HQL, being only used to sql, i dont understand whats wrong with my HQL. Any help would be greatly appriciated:
@Entity
public class KursKode {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String kursKode;
private boolean used;
@ManyToOne
@JoinColumn (name = "kursId")
@LazyCollection(LazyCollectionOption.FALSE)
private Kurs kurs;
....
}
Im trying to fetch only "KursKode"'s for a specific Kurs. And only "KursKodes" that have "used=false". So i tried this in my DAO:
List<KursKode> kursKodeList = getHibernateTemplate().find("from KursKode k where k.kurs.kursId = ? and not k.used", kursId);
But this gives me the following error:
Data Access Failure
unexpected AST node: . near line 1, column 74 [from no.dahlsdata.model.Kurs.KursKode k where k.kurs.kursId = ? and not k.used]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: . near line 1, column 74 [from no.dahlsdata.model.Kurs.KursKode k where k.kurs.kursId = ? and not k.used]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题很小。我忘了把 =false 放在最后。它应该是这样的:
Problem was only small. I forgot to put =false on the end. Here is what it should be: