命名查询中的错误 [英] Error in named queries
问题描述
我正在获取 org.hibernate.HibernateException:命名查询中的错误:getPreferenceById
,这是我的查询
I am getting org.hibernate.HibernateException: Errors in named queries: getPreferenceById
and this is my query
@NamedQueries({
@NamedQuery(name = "getPreferenceById",
query = "select p from Preference p where p.profile.id=:Id") })
这是我的偏好类
@Entity(name = "perference")
public class Preference {
@OneToOne
@JoinColumn(name = "id", nullable = false)
private Profile profile;
}
该查询用于获取给定profileId(id)的首选项,但它给出了错误.我在Profile类中有一个类似的命名查询,但是没有给出错误.
The query is for fetching the preference for the given profileId, (id), but it is giving error. I have a similar named query in the Profile class, but it is not giving error.
我在堆栈跟踪中找到了它,
I found this in the stacktrace,
Error in named query: getPreferenceById
org.hibernate.hql.internal.ast.QuerySyntaxException: Preference is not mapped
[select p from Preference p where p.profile.id=:Id]
我已将javax @Entity
批注添加到首选项类
I have added the javax @Entity
annotation to the preference class
此命名查询有什么问题?
What is wrong with this named query?
推荐答案
我终于通过将 NamedQueries
更改为 NativeNamedQueries
来解决了这个问题,我不知道它为什么起作用
I finally got that working by changing the NamedQueries
to NativeNamedQueries
i don't know why it worked
这篇关于命名查询中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!