命名Hibernate查询的“命名查询未知”?

时间:2012-04-21 18:12:32

标签: java hibernate

可能是什么问题?

@Entity
@NamedQueries( {
    @NamedQuery(name = User.ALL,
                query = "SELECT u FROM User u")
})

public class User {
    public static final String ALL = "User.all";
}

public class Service {
    find... with ... User.ALL
}

堆栈跟踪:

Caused by: org.hibernate.MappingException: Named query not known: User.all
    at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:93)
    at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1407)
    at $Session_a5ad46cfa25.getNamedQuery(Unknown Source)
    at $Session_a5ad46cf913.getNamedQuery(Unknown Source)
    at de.medicshare.dal.HibernateCrudServiceDAO.findUniqueWithNamedQuery(HibernateCrudServiceDAO.java:83)
    at $CrudServiceDAO_a5ad46cfa19.findUniqueWithNamedQuery(Unknown Source)
    at $CrudServiceDAO_a5ad46cfa1b.findUniqueWithNamedQuery(Unknown Source)
    at $CrudServiceDAO_a5ad46cf931.findUniqueWithNamedQuery(Unknown Source)
    at de.medicshare.pages.Signup.proceedSignup(Signup.java:82)
    at de.medicshare.pages.Signup.dispatchComponentEvent(Signup.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:923)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1106)
    ... 90 more

1 个答案:

答案 0 :(得分:2)

不确定这是否是您的问题,但请查看此帖子here

问题在于使用:

org.hibernate.annotations.Entity

而不是:

javax.persistence.Entity